code / tomo-json

Lines232 Tomo203 Markdown26 INI3
(19 lines)

JSON

This is a Tomo library for encoding/decoding JSON values.

Usage

>> j := JSON({"key1"=123, "key2"=[yes, {"ok"="inner"}, JSON.Null]})
= JSON.Object({"key1"=Number(123), "key2"=Array([Boolean(yes), Object({"ok"=String("inner")}), Null])})

say("$(j.encode())")
say("$(j.pretty_print())")

when JSON.parse("[1, null, true]") is Success(obj)
    >> obj
is Failure(msg)
    fail("Failed to parse JSON: $msg")
1 # JSON
3 This is a [Tomo](https://tomo.bruce-hill.com) library for encoding/decoding
4 JSON values.
6 ## Usage
8 ```tomo
9 >> j := JSON({"key1"=123, "key2"=[yes, {"ok"="inner"}, JSON.Null]})
10 = JSON.Object({"key1"=Number(123), "key2"=Array([Boolean(yes), Object({"ok"=String("inner")}), Null])})
12 say("$(j.encode())")
13 say("$(j.pretty_print())")
15 when JSON.parse("[1, null, true]") is Success(obj)
16 >> obj
17 is Failure(msg)
18 fail("Failed to parse JSON: $msg")
19 ```