This is a JSON parsing library for ZScript.
Includes a usage example and a small test suite.
It supports, in addition to strict JSON: trailing commas, single-quote strings, and single/multi-line comments (C/C++-style).
To use in your mod, just generate the prefixes, copy over the generated/ZJSON
folder, and add #include "ZJSON/Include.zs"
to your main ZScript file.
Run generate.sh [your prefix]
on linux/wsl/msys/cygwin. The prefixed files will be in the generated
folder.
Call JSON.parse
with a string that contains JSON text, it will return either a JsonElement
in case of success, or a JsonError
in case of failure. Call JsonElement::serialize
to generate JSON back from a JsonElement
.
- JsonError - NOT a Json Element. If
JSON.parse
return this, it means that the parsing failed, the error is inJsonError.what
, it contains line number and some extra information. - JsonElement - One of
JsonObject
,JsonArray
,JsonString
,JsonNumber
,JsonBool
, orJsonNull
- JsonObject - Hash Table that holds
JsonElement
values withString
keys - JsonArray - Dynamic Array that holds
JsonElement
values - JsonString - String Literal
- JsonNumber - One of
JsonInt
orJsonDouble
- JsonInt - Integral Literal
- JsonDouble - Decimal Literal
- JsonBool - A
true
/false
Literal - JsonNull - A
null
Literal