Canonicalize JSON with RFC 8785 (JCS) bytes
canonicalize_jsonGenerate RFC 8785 canonical JSON for signed threat feeds and tool-def pins. Rejects non-integers and lone surrogates with reason codes, enabling byte-for-byte verification.
Instructions
Return the RFC 8785 JSON Canonicalization Scheme serialization WARDEN uses for threat-feed signatures and tool-def pins, so another implementation can byte-check against it. Integers only inside ±(2^53−1); lone surrogates and non-integers are refused with a reason code, not escaped.
When to use: you are publishing or verifying a signed threat feed, hashing tool defs, or comparing two JSON documents that must agree regardless of key order. Subpath @aimarket/warden/jcs is the same function.
When NOT to use: scanning tool defs (static_scan_tools); pretty-printing for humans (this output is for bytes, not display).
Behaviour: local, no network. Pass either a parsed JSON value or a JSON string (string is parsed with parseJsonStrict first). Failure returns isError with CanonicalizationCode — it does not emit partial bytes.
Returns { canonical } or an error. Example: canonicalize_json({ value: { b: 1, a: 2 } }) → {"a":2,"b":1}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | JSON value to canonicalize, or a JSON string to parse first. Objects have keys sorted by UTF-16 code units. Numbers must be integers in ±(2^53−1). Do not pass undefined, functions, or cyclic structures. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| canonical | Yes | RFC 8785 canonical JSON text (UTF-8-ready string). Hash or sign these bytes, not JSON.stringify output. |