pub enum JsonValue {
JNull,
JBool { value: boolean },
JNumber { value: float },
JString { value: text },
JArray { pub items: vector<JsonValue> },
JObject { pub fields: vector<JsonField> },
JInteger { value: integer },
}
Typed union of JSON values. The discriminant (1..7) picks the active variant; variant data lives in the variant's fields. Matches the RFC 8259 kinds, plus JInteger for an integer-shaped number preserved to an exact integer (i64).
JInteger MUST stay the LAST variant: the store discriminant it gets (7) is hard-coded as JV_DISCR_INT in src/native.rs, and the existing variants' discriminants (1–6) must not shift.
pub struct JsonField {
pub name: text,
pub value: JsonValue,
}
One field of a JObject. A JObject keeps its fields as a vector<JsonField> in source order, so a lookup by name is a linear scan — fine for the object sizes typical in configuration / API responses.
pub fn json_parse(raw: text) -> JsonValue
Parse JSON text into a JsonValue tree. Malformed input returns JNull; the error trail is accessible via json_errors(). Every variant materialises (primitives, arrays, objects, nested containers); the entire tree lives in one store and frees as one unit when the root DbRef leaves scope.
loft match json_parse(raw) { JObject { fields } => for f in fields { handle(f) }, JArray { items } => for v in items { handle(v) }, JNull => println("parse error: {json_errors()}"), _ => println("unexpected root kind"), }
pub fn json_errors() -> text
Return a pipe-separated trail of JSON parse errors from the most recent json_parse call. Empty when the parse succeeded. Each entry carries an RFC 6901 path, a line:col location, and a context snippet.