Documentation
¶
Overview ¶
Package jsonstringify implements ECMAScript serialization for parsed JSON data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendCanonical ¶
AppendCanonical appends Canonicalize(raw) to dst. Text that JSON.stringify writes unchanged is appended without an intermediate copy, so a caller that reuses dst allocates nothing for it. On an error dst is returned unchanged.
func Canonicalize ¶
Canonicalize applies JSON.parse/stringify semantics to validated JSON, preserving object insertion order and lone UTF-16 surrogates. Text that JSON.stringify would write unchanged is copied, without a decode and re-encode.
func IsCanonical ¶
IsCanonical reports whether Canonicalize(text) would return text unchanged, as JSON.stringify(JSON.parse(text)) writes it; a false result does not say it would change. The text must be trimmed.
What the rewrite changes, and so what the scan refuses: whitespace between tokens; string escapes JSON.stringify does not write (\/, an uppercase-hex or non-control non-surrogate \u escape, \u000a for \n, a surrogate pair spelled as two escapes); invalid UTF-8; numbers that are not already the shortest ECMAScript form (-0, a trailing zero or exponent, more than 15 significant digits, below 1e-6); integer-like object keys, which JSON.stringify writes first; repeated object keys, where the last wins; and anything that is not a complete JSON value.
Types ¶
This section is empty.