/JSONx

Extended JSON parser for XVM

Primary LanguageXCMIT LicenseMIT

JSONx

Gitter

JSONx grammar

JSONx -> value eof
value -> object | array | reference | string | number
object -> '{' pairs '}' | '{' '}'
pairs -> pair (',' pair)*
pair -> string ':' value
array -> '[' elements ']' | '[' ']'
elements -> value (',' value)*
reference -> '$' '{' string (':' string)? '}'

string -> ("(?:[^"\\]|\\.)*")
number -> ([+-]?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][+-]?[0-9]+)?)
eof -> !.

Example

Multi-file JSON load

####example.jsonx

{
  "greetings": ${ "greetings_file.jsonx": "." }
}

####greetings_file.jsonx

"Hello JSONx"
import JSONxLoader
result = JSONxLoader.load("example.jsonx")
>>> { "greetings" : "Hello JSONx" }

Parse string

import JSONx
json_string = """
{
    "name": "Alexander",
    "nickname": "Yukikaze",
    "etc": ["list", "of", "anything", 1, 2, 3.14, true, false, null]
}
"""
result = JSONx.parse(json_string)