Json

Inherits from: Object

Encode and decode JSON data.

Json converts between Maggie objects and JSON strings. Dictionaries map to JSON objects, Arrays to JSON arrays, Strings/Numbers/Booleans/nil map directly.

Example
Json encode: #{'name' -> 'Alice'. 'age' -> 30}
  "=> '{\"age\":30,\"name\":\"Alice\"}'"

Json decode: '{"x": 1, "y": [2, 3]}'
  "=> a Dictionary"

Json encodePretty: #{'key' -> 'value'}
  "=> '{\n  \"key\": \"value\"\n}'"

Class Methods

primitives

class primDecode:
class primEncode:
class primEncodePretty:

uncategorized

class decode:

Decode a JSON string into Maggie objects.

JSON objects become Dictionaries, arrays become Arrays, strings become Strings, integers become SmallIntegers, decimals become Floats, booleans become true/false, and null becomes nil.

Raises JsonParseError on malformed input.

Example
Json decode: '42'                "=> 42"
Json decode: '"hello"'           "=> 'hello'"
Json decode: '[1, 2, 3]'        "=> #(1 2 3)"
Json decode: 'null'             "=> nil"
class encode:

Encode a Maggie object as a compact JSON string.

Supported types: Dictionary, Array, String, SmallInteger, Float, true, false, nil.

Example
Json encode: 42                    "=> '42'"
Json encode: 'hello'              "=> '\"hello\"'"
Json encode: true                 "=> 'true'"
Json encode: nil                  "=> 'null'"
Json encode: #(1 2 3)            "=> '[1,2,3]'"
class encodePretty:

Encode a Maggie object as a pretty-printed JSON string with two-space indentation.

Example
Json encodePretty: #{'a' -> 1}