Documentation
¶
Overview ¶
Package jsonx is JSON.stringify.
Every byte this program emits as JSON goes through here, because three of those byte sequences are signed or stored and replayed (the share JWT, the webhook envelope, a delivery's payload), every API response is two-space pretty-printed, and a Go encoder left to its defaults does three things JavaScript does not: sorts map keys, HTML-escapes `<>&`, and appends a newline. So: structs (field order) or *omap.Map (insertion order), never map[string]any; SetEscapeHTML(false); the trailing newline trimmed. Numbers are emitted the way JSON.stringify emits them — an integer is an integer, a float is the shortest round-trippable form — which is what encoding/json does for int64/float64 when the value has the right static type. Keep it typed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool, Str and Int are the pointer helpers for the tri-state and nullable-not-absent fields: `*bool` without omitempty marshals `null` when nil and `false` when false — the distinction invariant 11 exists to keep.
func MarshalIndent ¶
MarshalIndent is JSON.stringify(v, null, 2).
func Number ¶
Number renders a float64 the way JavaScript's Number.prototype.toString does (which is also how JSON.stringify renders it): integers without a fraction, otherwise the shortest representation that round-trips, with exponent notation outside [1e-7, 1e21). NaN and ±Infinity are "null" in JSON and "NaN"/"Infinity" in String() — callers that need the latter use NumberString.
func NumberString ¶
NumberString is String(number) in JavaScript.
Types ¶
type Object ¶
type Object []KV
Object is an ordered list of key/value pairs that marshals in order — for ad-hoc response bodies built at a route, where a struct would be ceremony. Prefer structs for anything reused.
func O ¶
O builds an Object from alternating keys and values: O("a", 1, "b", "x"). The shape every event payload takes — ordered like the TS object literal it replaces, without a struct per event.
func (Object) MarshalJSON ¶
MarshalJSON emits the pairs in order.