json

native module

JSON parse/serialize. import "json". Objects ↔ maps, arrays ↔ lists, numbers → int (no ./e) or float, true/falsebool. JSON null decodes to nil (Zinc's nil is a real, writable value).

json.parse(s: string) => (any, string?)

Parse a JSON document. (nil, "invalid JSON") on malformed input.

json.stringify(value: any, indent: int?) => (string, string?)

Serialize to JSON; indent spaces per level (default 0 = compact). nilnull. Errs if the value contains a non-finite float (NaN/Infinity), an unrepresentable kind (struct instance, closure, enum value, def, module, iterator) — JSON cannot represent any of these — or if two map entries would render to the same JSON key (e.g. int key 1 and string key "1"), which would silently clobber one entry.

On this page