Json.canonicalize
Serializes a value to a canonical JSON string as defined by RFC 8785 (JSON Canonicalization Scheme).
- Object keys are sorted recursively by UTF-16 code unit comparison. - Primitives are serialized per ECMAScript rules (no trailing zeros on numbers, etc.). - No whitespace is inserted.
Imports
Named
import { Json } from 'ox'Examples
import { Json } from 'ox'
const json = Json.canonicalize({ b: 2, a: 1 })
'{"a":1,"b":2}'import { Json } from 'ox'
const json = Json.canonicalize({ z: [3, { y: 1, x: 2 }], a: 'hello' })
'{"a":"hello","z":[3,{"x":2,"y":1}]}'Definition
function canonicalize(
value: unknown,
): stringSource: src/core/Json.ts
Parameters
value
- Type:
unknown
The value to canonicalize.
Return Type
The canonical JSON string.
string

