Skip to content
FutureBlitz

    Install

    Import std.data.json

    Json

    std.data.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)

    std/data/json.fb, line 431

    • @PanicsAtCaller Public Static Method Read(text: String, depth: Int = DEPTH): Value Throws ParseError static 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 past depth. Panics unless depth is 1 or more.

    • @PanicsAtCaller Public Static Method Read(bytes: UInt8[], depth: Int = DEPTH): Value Throws ParseError static method #

      The Value of UTF-8 bytes' JSON, as Read of text gives it.

    • @PanicsAtCaller Public Static Method Write(value: Value, indent: Int = 0): String static method #

      value as JSON, as JsonWriter writes it with indent: 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 ParseError static method #

      The T of text's JSON: Read's Value, made a T by Load<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 ParseError static method #

      The T of UTF-8 bytes' JSON, as Read<T> of text gives it.

    • @PanicsAtCaller Public Static Method Write<T>(x: T, indent: Int = 0): String static method #

      x as JSON: Save's Value of it, written as Write writes a Value.

    Report an issue with this page or with FutureBlitz on GitHub.