Skip to content

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

License

Notifications You must be signed in to change notification settings

RicardoLuis0/ZJSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published