lloyd / yajl

A fast streaming JSON parsing library in C.
http://lloyd.github.com/yajl
ISC License
2.15k stars 435 forks source link

Add support for JSON5 #211

Open anjohnson opened 6 years ago

anjohnson commented 6 years ago

The changes in this PR add support to yajl-2.1 for parsing and generating JSON5. Included are the code and tests for:

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.