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}Related
larzjsonJSON parse/stringify, pure Larzscript→Read and Parse a CSV File in LarzscriptParse CSV text into rows, or straight into dicts keyed by header - including quoted fields with embedded commas.→Encode and Decode Base64 in LarzscriptBase64-encode arbitrary text (or decode it back), the standard way binary-ish data travels safely through text-only channels like JSON or URLs.→Parse a URL in LarzscriptBreak a URL into its scheme, host, path and query parameters, and safely join a base URL with a relative path.→