JSON: building values

pub fn to_json(self: const JsonValue) -> text

Render a JsonValue to canonical RFC 8259 JSON text. Every variant serialises; JArray / JObject recurse through their children (full tree serialisation, nested containers walk naturally). Strings escape ", \\, and ASCII control bytes; UTF-8 passes through verbatim. Non-finite numbers render as null.

pub fn to_json_pretty(self: const JsonValue) -> text

to_json_pretty produces 2-space indented, one-element-per-line output for non-empty JArray / JObject containers. Empty containers render [] / {} (no newline padding). Primitives are byte-identical to to_json (no nested structure to indent). After object keys the colon is followed by a single space ("k": v). Useful for golden-file tests and log output.

pub fn json_null() -> JsonValue

Build a JsonValue set to the JNull variant. Useful in test fixtures and reply-construction code that needs a known-null JsonValue without going through json_parse("null").

pub fn json_bool(v: boolean) -> JsonValue

Build a JsonValue set to the JBool variant carrying the supplied boolean payload.

pub fn json_number(v: float?) -> JsonValue

Build a JsonValue set to the JNumber variant carrying the supplied float payload. Non-finite inputs (float null = NaN, or ±Inf) produce JNull with a diagnostic in json_errors() — mirrors the RFC 8259 constraint that JSON numbers must be finite. The parameter is float? because handling a null/NaN input IS its contract (→ JNull); a finite float passes as a non-null value into the nullable slot as usual.

pub fn json_string(v: text) -> JsonValue

Build a JsonValue set to the JString variant carrying the supplied text payload. The text is copied into the JsonValue's own store, so the returned value owns the string independently of the argument's lifetime.

pub fn json_array(items: const vector<JsonValue>) -> JsonValue

Build a JsonValue set to the JArray variant carrying the supplied items. Each element is deep-copied into the new tree's arena via the shared dbref_to_parsed walker, so nested containers and arena-origin subtrees (e.g. a captured field() result) embed correctly. Empty input produces a real empty JArray.

pub fn json_object(fields: const vector<JsonField>) -> JsonValue

Build a JsonValue set to the JObject variant carrying the supplied fields. Each field's value deep-copies via the same dbref_to_parsed walker as json_array, so a JObject can carry captured-subtree JArray / JObject values. Empty input produces a real empty JObject.