Adds support for JSON5, while retaining support for other JSON variants.
Adds test examples (with JSON input and CSV output) for each documented kind of supported JSON variant.
Removed my own crude regex-based support for unquoted keys (now done by JSON5).
Removed my own crude regex-based approach to removing smart quotes (this appears no longer unnecessary).
This means we now support:
JSON, using the browser's native JSON.parse() function
JSON5, using the JS-based JSON5 parser distributed at json5/json5. (Provides support for inline JS comments, unquoted keys, single-quoted keys and strings, line breaks inside strings,, trailing commas, positive + signs on numbers -- see below.)
JSON Lines, a special format which allows one-JSON-object-per-line. This is done using crude regexes on my part.
A trailing comma at the end of the JSON input. Done using a crude regex on my part.
For an example of what JSON5 supports, this is the canonical example from their README:
{
// comments
unquoted: 'and you can quote me on that',
singleQuotes: 'I can use "double quotes" here',
lineBreaks: "Look, Mom! \
No \\n's!",
hexadecimal: 0xdecaf,
leadingDecimalPoint: .8675309, andTrailing: 8675309.,
positiveSign: +1,
trailingComma: 'in objects', andIn: ['arrays',],
"backwardsCompatible": "with JSON",
}
Putting the JSON5 example above into the JSON-to-CSV converter (as of this PR) parses this as expected and renders it:
This pull request:
This means we now support:
JSON.parse()
functionjson5/json5
. (Provides support for inline JS comments, unquoted keys, single-quoted keys and strings, line breaks inside strings,, trailing commas, positive+
signs on numbers -- see below.)For an example of what JSON5 supports, this is the canonical example from their README:
Putting the JSON5 example above into the JSON-to-CSV converter (as of this PR) parses this as expected and renders it:
All tests produce the expected output.