API reference › @evolu/common › Buffer › encodeJsonValue
function encodeJsonValue(buffer: Buffer, value: JsonValue): void;
Defined in: packages/common/src/Buffer.ts:296
Encodes a JsonValue using the MessagePack format.
Example
import {
assertEqual,
createBuffer,
encodeJsonValue,
JsonValue,
} from "@evolu/common";
const buffer = createBuffer();
const value = JsonValue.orThrow({ name: "Ada" });
encodeJsonValue(buffer, value);
assertEqual(
buffer.unwrap(),
new Uint8Array([0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61]),
);
Encoding is artificially limited to 1,000 nested arrays or objects to keep recursive encoding and decoding safe and symmetric. JSON data should not require such depth; flatten or split deeply nested data, or use a purpose-built serialization format.