Import std.data.json
Json
struct
Public Struct Json
A document's Value, and a Value's document.
Examples
Local document = Try Json.Read(r"""
{"name": "Ada", "langs": ["en", "fr"], "age": 36}
""")
Expect(document.Path("langs[1]")?.AsString() == "fr")
Expect(document.Path("age")?.AsInt() == 36)
Expect((Try Json.Read(Json.Write(document))) == document)-
@PanicsAtCaller Public Static Method Read(text: String, depth: Int = DEPTH): Value Throws ParseErrorstatic method #The Value of
text's JSON: an object as an OBJECT, its keys in order, the last of a key that repeats where its first was, and an integer that fits an Int64 as an INT, one past an Int64's largest that fits a UInt64 as a UINT, and any other number as a DOUBLE. Throws a ParseError as JsonReader's Next does, and for arrays and objects nested pastdepth. Panics unlessdepthis 1 or more. -
@PanicsAtCaller Public Static Method Read(bytes: UInt8[], depth: Int = DEPTH): Value Throws ParseErrorstatic method #The Value of UTF-8
bytes' JSON, as Read of text gives it. -
valueas JSON, as JsonWriter writes it withindent: a DOUBLE with a point or an exponent, so it reads back as one, and BYTES, which JSON has no kind for, as a string of their base64 (RFC 4648's, with '=' padding). Panics for a DOUBLE that's NaN or an infinity, which JSON doesn't have, or an indent below 0. -
@PanicsAtCaller Public Static Method Read<T>(text: String, depth: Int = DEPTH): T Throws ParseErrorstatic method #The T of
text's JSON: Read's Value, made a T byLoad<T>. Throws Read's ParseErrors, and Load's, whose Path says where in the document a value doesn't fit.Examples
Struct Player Field Name: String Field Level: Int End Struct Local player = Try Json.Read<Player>(r""" {"Name": "Ada", "Level": 3} """) Expect(player.Name == "Ada" && player.Level == 3) Local back = Try Json.Read<Player>(Json.Write(player)) Expect(back.Name == "Ada") -
@PanicsAtCaller Public Static Method Read<T>(bytes: UInt8[], depth: Int = DEPTH): T Throws ParseErrorstatic method #The T of UTF-8
bytes' JSON, asRead<T>of text gives it. -
xas JSON: Save's Value of it, written as Write writes a Value.
Report an issue with this page or with FutureBlitz on GitHub.