jsonstringify

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 9 Imported by: 0

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

func AppendCanonical(dst, raw []byte) ([]byte, error)

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

func Canonicalize(raw []byte) ([]byte, error)

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

func IsCanonical(text []byte) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL