std.json
std.json provides JSON parsing and stringification with full nesting support
(preserves arrays, objects, and primitives).
Reference
parse(str) // JSON string -> scrii value
stringify(value[, indent]) // value -> JSON string
| Function | Description |
|---|---|
parse(str) | Parse a JSON string into a Scrii value (object/array/primitive) |
stringify(value[, indent]) | Serialize a Scrii value to a JSON string; indent pretty-prints |
Examples
var data = std.json.parse('{"ok": true, "n": 42}')
print(data.ok) // true
print(data.n) // 42
var obj = {ok: true, nested: {a: [1, 2]}}
var s = std.json.stringify(obj, 2)
print(s)
// {
// "ok": true,
// "nested": {
// "a": [1, 2]
// }
// }
// round-trip preserves structure
var original = {name: "Ada", scores: [10, 20, {x: 3}]}
var text = std.json.stringify(original)
var copy = std.json.parse(text)
print(copy.scores[2].x) // 3
stringify with an indent argument produces indented output; without it the
result is compact.