Serializes a value to JSON and encodes it as UTF-8 bytes.
A one-call replacement for new TextEncoder().encode(JSON.stringify(value)), handy for the
byte-oriented publish / send / writeFile APIs. Pair with decodeJson to round-trip.
Parameters
value: unknown
The value to serialize.
Optionalspace: number
Optional JSON.stringify indentation (number of spaces); omit for compact output.
Returns Uint8Array
The UTF-8 bytes of the JSON text.
Since
1.0.4
Example
import { encodeJson } from'edgeport/util';
encodeJson({ ok:true }); // Uint8Array of '{"ok":true}'
Serializes a value to JSON and encodes it as UTF-8 bytes.
A one-call replacement for
new TextEncoder().encode(JSON.stringify(value)), handy for the byte-orientedpublish/send/writeFileAPIs. Pair with decodeJson to round-trip.