Json
Overview
The json API provides basic serialization between Fan Maps, Lists, and most primitives with Javascript Object Notation (JSON).
There are plans to provide detailed type information about Fan types as part of the JSON serialization at some point, but currently the following are supported:
Refer to json.org for more information.
Writing Json
Writing a Map is accomplised via write
which writes a given map to an OutStream
. To write to standard out:
map := ["key":"value", "intKey":123] Json.write(map, Sys.out)
Reading Json
Reading JSON takes raw JSON from a stream and produces a Map
.
Given the following json:
str := "{\"k1\":\"v1\", \"k2\":3.4159, \"k3\":[1,2,3], \"k4\": {\"m1\":true, \"m2\":null}}" input := InStream.makeForStr(str) Str:Obj? data = Json.read(input) data["k1"] -> "v1"