Data formats · real, tested code

Parse JSON in Larzscript

Parse a JSON string into real Larzscript dicts and lists, and turn data back into JSON text.

json.parse() and json.stringify() are pure Larzscript, no C library or OS dependency; json.get() walks a dotted path through nested data in one call.

larzscript pkg install json

Code

import "json" as json

let data = json.parse("{\"name\": \"Ada\", \"langs\": [\"Larzscript\", \"Python\"], \"active\": true}")
print(data["name"], data["langs"][0])
print(json.get(data, "langs.1", nil))
print(json.stringify({"ok": true, "count": 3}))
Output
Ada Larzscript
Python
{"ok":true,"count":3}