JSON, YAML, and TOML#

Meta: short page. The defining characteristic is type-driven parsing — JSON.decode produces values of the expected type. Open with that.

Each format is a codec namespace — JSON, YAML, TOML — with matching encode / decode static methods. The names double as scalar types (:: JSON) and are owned by Dang, so they work with no schema import; an in-scope scalar of the same name (e.g. Dagger's JSON) merges with the codec rather than colliding (see Enums and scalars).

Parsing#

let summary: Summary! = JSON.decode("""{"name": "test", "count": 42}""")
let status: Status! = JSON.decode("\"PASSED\"")
let cfg = YAML.decode("name: foo\ncount: 1")
let settings: Settings! = TOML.decode("count = 1")

Serialization#

Coercion during parsing#

Common errors#

All of these are catchable with try/catch (Errors: try, catch, raise).

Meta: A side-by-side "JSON in / Dang value out" table would be a nice teaching tool.