std.json
rfc 8259; parse into an arena tree, write with Out
JsonError
Section titled “JsonError”pub JsonError :: errors { unexpected_end, unexpected_byte, bad_number, bad_string, too_deep, trailing_text,}unexpected_end: the text ends inside a valueunexpected_byte: a byte that cannot stand where it standsbad_string: bad escape or control char in a stringtoo_deep: arrays and objects nested deeper than 512trailing_text: something after the value
pub Kind :: enum { null_value, boolean, number, string, array, object,}pub Value :: struct { kind: Kind, flag: bool, number: f64, text: []const u8, items: []Value, keys: [][]const u8,}flag: the value of a booleannumber: the value of a numbertext: string value, or a number’s source textitems: array elements or object member valueskeys: object member names, parallel toitems
Value.get
Section titled “Value.get”pub get :: fn(self: Self, key: []const u8) -> Valuefirst member named key; null value if none or not an object
Value.at
Section titled “Value.at”pub at :: fn(self: Self, i: usize) -> Valuenull value past the end or if not an array
Value.len
Section titled “Value.len”pub len :: fn(self: Self) -> usizeelements or members; 0 for anything else
Value.is_null
Section titled “Value.is_null”pub is_null :: fn(self: Self) -> boolValue.as_f64
Section titled “Value.as_f64”pub as_f64 :: fn(self: Self) -> ?f64Value.as_i64
Section titled “Value.as_i64”pub as_i64 :: fn(self: Self) -> ?i64whole numbers that fit i64; exact over the full range
Value.as_text
Section titled “Value.as_text”pub as_text :: fn(self: Self) -> ?[]const u8Value.as_bool
Section titled “Value.as_bool”pub as_bool :: fn(self: Self) -> ?boolnull_value
Section titled “null_value”pub null_value :: fn() -> Valuealso what failed lookups return, so lookup chains need no checks
pub parse :: fn(text: []const u8, a: *Arena) -> Value ! JsonErrortree in a; skips a utf-8 bom; escape-free strings slice text; max depth 512
pub Out :: struct { w: *Writer, indent: usize, depth: usize, first: bool, after_key: bool, failed: bool,}streaming writer; does commas, quotes, escapes; write errors show in finish
indent: spaces a level; 0 writes it all on one linefirst: nothing written yet at this depthafter_key: a key was written: its value comes next
Out.begin_object
Section titled “Out.begin_object”pub begin_object :: fn(self: *Self)Out.end_object
Section titled “Out.end_object”pub end_object :: fn(self: *Self)Out.begin_array
Section titled “Out.begin_array”pub begin_array :: fn(self: *Self)Out.end_array
Section titled “Out.end_array”pub end_array :: fn(self: *Self)Out.key
Section titled “Out.key”pub key :: fn(self: *Self, name: []const u8)next member’s name; write its value right after
Out.string
Section titled “Out.string”pub string :: fn(self: *Self, s: []const u8)Out.int
Section titled “Out.int”pub int :: fn(self: *Self, v: i64)Out.uint
Section titled “Out.uint”pub uint :: fn(self: *Self, v: u64)Out.float
Section titled “Out.float”pub float :: fn(self: *Self, v: f64)up to 15 significant digits; NaN/inf written as null
Out.boolean
Section titled “Out.boolean”pub boolean :: fn(self: *Self, v: bool)Out.null_value
Section titled “Out.null_value”pub null_value :: fn(self: *Self)Out.value
Section titled “Out.value”pub value :: fn(self: *Self, v: Value)whole tree; numbers written as they were read
Out.finish
Section titled “Out.finish”pub finish :: fn(self: *Self) -> void ! IoError.write_failed if any write failed
writer
Section titled “writer”pub writer :: fn(w: *Writer) -> Outsingle line
pretty
Section titled “pretty”pub pretty :: fn(w: *Writer, indent: usize) -> Outone member/element per line, indent spaces per level
stringify
Section titled “stringify”pub stringify :: fn(a: *Arena, v: Value) -> []const u8one line, in a