Inherited from v1.0.0

json module

Two functions: parse JSON text into a bnl value, and serialize a bnl value to JSON text.

import "json" as json;

var obj = json.parse('{"name": "Alice", "age": 25}');
print(obj.name);          // Alice

var text = json.stringify({ ok: true, items: [1, 2, 3] });
print(text);              // {"ok":true,"items":[1,2,3]}

API

FunctionDescription
json.parse(text) → valueParse JSON into bnl value (number / string / bool / null / list / map). On malformed input, prints to stderr and returns null.
json.stringify(value) → stringSerialize a value to compact JSON.

Type mapping

JSONbnl
numbernumber
stringstring
true / falsebool
nullnull
[...]list
{...}map