Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 1.79 KB

README.md

File metadata and controls

28 lines (20 loc) · 1.79 KB

ZJSON - ZScript JSON Parser (with trailing comma and single/multi-line comment support)

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.

Generating Prefixes:

Run generate.sh [your prefix] on linux/wsl/msys/cygwin. The prefixed files will be in the generated folder.

How to Use:

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.

Types:

  • JsonError - NOT a Json Element. If JSON.parse return this, it means that the parsing failed, the error is in JsonError.what, it contains line number and some extra information.
  • JsonElement - One of JsonObject, JsonArray, JsonString, JsonNumber, JsonBool, or JsonNull
  • JsonObject - Hash Table that holds JsonElement values with String keys
  • JsonArray - Dynamic Array that holds JsonElement values
  • JsonString - String Literal
  • JsonNumber - One of JsonInt or JsonDouble
  • JsonInt - Integral Literal
  • JsonDouble - Decimal Literal
  • JsonBool - A true/false Literal
  • JsonNull - A null Literal