isCanonicalJson
Checks whether a value is a string that is already canonical JSON (RFC 8785, JSON
Canonicalization Scheme) — byte for byte what stringify(value, 'canonical') from
@helpers4/json would write for the value it holds.
That means: no whitespace outside strings, object keys sorted by UTF-16 code units, no
duplicate keys, numbers in their shortest ECMAScript form (1, not 1.0 or 1e0), strings
with only the escapes JSON.stringify uses, and no number beyond what a double holds exactly.
Available since v3.1.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
Section titled “Returns”value is string — true if value is a string in canonical JSON form
Examples
Section titled “Examples”Check canonical JSON
Section titled “Check canonical JSON”Sorted keys, no whitespace, shortest numbers (RFC 8785).
Valid JSON is not always canonical
Section titled “Valid JSON is not always canonical”Unsorted keys, whitespace or 1.0 instead of 1 all fail.
