The changes in this PR add support to yajl-2.1 for parsing and generating JSON5.
Included are the code and tests for:
Object keys may be an unquoted identifier name if they match the regex [$_A-Za-z][$_A-Za-z0-9]*.
Objects may have a trailing comma.
Arrays may have a trailing comma.
Strings may be single-quoted.
Strings may span multiple lines by escaping the newline character(s) which are then excluded from the string.
Strings may include hex character escapes using \xXX where XX are 2 hex digits giving a character number in the Basic Latin or Latin-1 Supplement Unicode character ranges (U+0000 through U+00FF).
Numbers may be hex integers.
Numbers may have a leading or trailing decimal point.
Numbers may be ±Infinity or NaN.
Numbers may being with a + sign.
Turning on JSON5 for the parser also allows comments, which are part of the JSON5 spec.
The yajl generator also supports JSON5 with a configuration flag, permitting it to output ±Infininty and NaN values and will omit quotes from object keys that follow the appropriate rules.
The json_reformat and json_verify (and yajl_test) programs take a -5 option to allow JSON5 input, and json_reformat has a separate -g flag to generate JSON5 output. The yajl_tree code enables JSON5 support unilaterally, as there was no existing configuration API for it.
I also worked on the Doxygen markup, in addition to documenting the JSON5 additions. Some of these changes were probably more extensive than they could have been, so those are the last in the series of commits included.
And finally one other small but important change to know about: These characters [ and ] are brackets, these { and } are braces; I swapped the tag names that the lexer returns and adjusted the parser to match (my brain was getting too confused, or maybe it was just OCD, but I had to fix these).
This branch and PR was modified in August 2020 to correct some misunderstandings of the JSON5 spec on my part — I added the \x hex character escapes, and removed the checks for JavaScript keywords.
The changes in this PR add support to yajl-2.1 for parsing and generating JSON5. Included are the code and tests for:
[$_A-Za-z][$_A-Za-z0-9]*
.\xXX
whereXX
are 2 hex digits giving a character number in the Basic Latin or Latin-1 Supplement Unicode character ranges (U+0000 through U+00FF).The yajl generator also supports JSON5 with a configuration flag, permitting it to output ±Infininty and NaN values and will omit quotes from object keys that follow the appropriate rules.
The
json_reformat
andjson_verify
(andyajl_test
) programs take a-5
option to allow JSON5 input, andjson_reformat
has a separate-g
flag to generate JSON5 output. The yajl_tree code enables JSON5 support unilaterally, as there was no existing configuration API for it.I also worked on the Doxygen markup, in addition to documenting the JSON5 additions. Some of these changes were probably more extensive than they could have been, so those are the last in the series of commits included.
And finally one other small but important change to know about: These characters
[
and]
are brackets, these{
and}
are braces; I swapped the tag names that the lexer returns and adjusted the parser to match (my brain was getting too confused, or maybe it was just OCD, but I had to fix these).This branch and PR was modified in August 2020 to correct some misunderstandings of the JSON5 spec on my part — I added the \x hex character escapes, and removed the checks for JavaScript keywords.