Import with #import "std/json_document".
JsonKind :: enum { Missing = 0; Null = 1; False = 2; True = 3; Number = 4; String = 5; Array = 6; Object = 7; }JsonEraser :: #type (context: *void, bytes: []u8)JsonNoErase :: (context: *void, bytes: []u8)JsonNode :: struct { kind: JsonKind; text: string; owned_text: Vec(u8); key: string; owned_key: Vec(u8); first: s32; last: s32; next: s32; count: s32; }JsonDocument :: struct { nodes: Vec(JsonNode); root: s32; error: string; error_at: s64; erase: JsonEraser; erase_context: *void; }JsonStyle :: struct { indent: s32; item_separator: string; key_separator: string; ascii: bool; sort_keys: bool; python_floats: bool; }JsonPythonStyle :: (indent: s32, ascii: bool, sort_keys: bool, python_floats: bool) -> JsonStyleThe style of Python's json.dumps(value, indent=INDENT); a negative INDENT stands for indent=None. ASCII escapes are on, as ensure_ascii's default.
JsonCompactStyle :: (ascii: bool, sort_keys: bool) -> JsonStyleOne line with separators=(',', ':').
JsonSetEraser :: (document: *JsonDocument, erase: JsonEraser, context: *void)Register an optional owner-supplied eraser before building/copying private text. It receives actual owned bytes, including failed partial strings. Call JsonReset before the document leaves scope; borrowed source bytes stay the caller's responsibility. No cryptographic dependency lives in JSON.
JsonReset :: (document: *JsonDocument)JsonRead :: (document: *JsonDocument, text: string, erase: JsonEraser, erase_context: *void) -> boolReads TEXT as the document's root, after clearing it. False, with error and error_at set, when TEXT is not one complete JSON value.
JsonKindOf :: (document: *JsonDocument, node: s32) -> JsonKindJsonCount :: (document: *JsonDocument, node: s32) -> s32The number of elements or members.
JsonFirst :: (document: *JsonDocument, node: s32) -> s32The first element or member, then each next one, then -1.
JsonNext :: (document: *JsonDocument, node: s32) -> s32JsonKey :: (document: *JsonDocument, node: s32) -> TextA member's name.
JsonKeyInto :: (document: *JsonDocument, node: s32, output: *Vec(u8)) -> boolJsonMember :: (document: *JsonDocument, object: s32, key: string) -> s32The object's last member named KEY, or -1.
JsonElement :: (document: *JsonDocument, array: s32, index: s32) -> s32The array's element at INDEX, or -1.
JsonString :: (document: *JsonDocument, node: s32) -> TextA string's value; "" for anything else.
JsonStringInto :: (document: *JsonDocument, node: s32, output: *Vec(u8)) -> boolJsonIs :: (document: *JsonDocument, node: s32, value: string) -> boolWhether NODE is the string VALUE, without copying it.
JsonNumberText :: (document: *JsonDocument, node: s32) -> TextA number's text as written; "" for anything else.
JsonNumberTextInto :: (document: *JsonDocument, node: s32, output: *Vec(u8)) -> boolJsonInteger :: (document: *JsonDocument, node: s32) -> (s64, bool)A whole number in the signed 64-bit range, without a fraction or exponent. Returns false for overflow; the document retains the original number text.
JsonBool :: (document: *JsonDocument, node: s32) -> (bool, bool)JsonNewNull :: (document: *JsonDocument) -> s32JsonNewBool :: (document: *JsonDocument, value: bool) -> s32JsonNewInteger :: (document: *JsonDocument, value: s64) -> s32JsonNewNumber :: (document: *JsonDocument, text: string) -> s32A number written as TEXT, which must be a valid JSON number.
JsonNewString :: (document: *JsonDocument, value: string) -> s32JsonNewStringCopy :: (document: *JsonDocument, value: string) -> s32Own VALUE when the caller's string storage will end before this document. JsonNewString above deliberately retains its borrowed-input contract.
JsonNewArray :: (document: *JsonDocument) -> s32JsonNewObject :: (document: *JsonDocument) -> s32JsonAppend :: (document: *JsonDocument, array: s32, child: s32) -> boolAdds CHILD, a node not yet in any container, to the end of ARRAY.
JsonSet :: (document: *JsonDocument, object: s32, key: string, child: s32) -> boolSets OBJECT's member KEY to CHILD, a node not yet in any container: a present member is replaced where it stands, as a Python dict keeps its place, and a new one goes last.
JsonSetCopy :: (document: *JsonDocument, object: s32, key: string, child: s32) -> boolLike JsonSet, with a document-owned copy of KEY. Use this when the caller's key storage will be released before the document is written.
JsonRemove :: (document: *JsonDocument, object: s32, key: string) -> boolRemoves every member named KEY; false when there was none.
JsonClear :: (document: *JsonDocument, node: s32)Empties an array or object.
JsonCopy :: (target: *JsonDocument, source: *JsonDocument, node: s32) -> s32A deep copy of SOURCE's NODE as a new node of TARGET, which may be the same document; returns it, or -1 for a missing node.
JsonQuoteInto :: (output: *Vec(u8), value: string, ascii: bool) -> boolAppends VALUE as a quoted JSON string, escaped as json.dumps escapes it.
JsonQuote :: (value: string, ascii: bool) -> TextJsonWrite :: (document: *JsonDocument, node: s32, style: JsonStyle) -> TextNODE and everything in it as JSON text in STYLE, without a final newline.
JsonWriteInto :: (output: *Vec(u8), document: *JsonDocument, node: s32, style: JsonStyle) -> boolAppend to caller-owned storage. It must not back this document's borrowed input, or be one of its owned node buffers. Discard partial output on error. Sensitive callers start with empty/wiped storage or pre-reserve its lifetime maximum; they erase their own output and borrowed input after use.