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
| Function | Description |
|---|---|
json.parse(text) → value | Parse JSON into bnl value (number / string / bool / null / list / map). On malformed input, prints to stderr and returns null. |
json.stringify(value) → string | Serialize a value to compact JSON. |
Type mapping
| JSON | bnl |
|---|---|
number | number |
string | string |
true / false | bool |
null | null |
[...] | list |
{...} | map |