Documentation
¶
Overview ¶
Package jsonx builds JSON documents with the exact byte-level semantics of a chain of sjson v1.0.4 Set/SetRaw calls — new keys PREPEND (so sequential inserts land in reverse order), existing values replace in place, "-1" appends to arrays, numeric indexes null-pad — but serialized ONCE instead of re-copying the whole document per call. Envelope byte-identity (golden tests, traces) depends on these semantics; sjson is pinned at v1.0.4 in go.mod for the same reason.
Error semantics also mirror the ubiquitous `doc, _ = sjson.Set(...)` call shape: an invalid path (unescaped *?#, empty path) or an unmarshalable value poisons the document to "" and later Sets rebuild from empty, exactly like the chained form.
Limitations (enforced by convention, exercised by the equivalence fuzz): SetRaw values must be valid JSON — descending a path *through* an invalid raw blob is undefined; and a Builder is not safe for concurrent use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendStringify ¶
func MustMarshalString ¶
MustMarshalString / AppendStringify replicate sjson v1.0.4's string encoder (MIT, github.com/tidwall/sjson): fast-quote when every byte is plain printable ASCII, else encoding/json (which HTML-escapes).
func SetMany ¶
SetMany applies the sets to doc with the exact semantics of the sequential `doc, _ = sjson.Set(doc, path, v)` chain. When every target path already exists (the steady-state for periodic re-stamps like budget sync), it resolves all spans in one pass and splices one output buffer instead of copying the whole doc per set; otherwise it falls back to the sequential chain, so byte-identity holds by construction.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder accumulates Set/SetRaw operations into a node tree and serializes once. The zero value / New() is the empty document "" (matching a chain that starts from ""); NewObject() matches a chain that starts from "{}" — the two differ when the first path segment is numeric (sjson turns an empty doc into an array, but inserts a string key into "{}").
func NewArray ¶
func NewArray() *Builder
NewArray starts from "[]" (the `sjson.Set("[]", "-1", ...)` append seed used by list builders).
func (*Builder) Set ¶
Set encodes v exactly as sjson.Set would (strings and []byte via appendStringify, sized ints via FormatInt, float32 via the same widen-then-'f' quirk, everything else via encoding/json) and applies it at path.