Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON5 support, and comprehensive tests and examples #224

Merged
merged 1 commit into from
Oct 27, 2018
Merged

Conversation

konklone
Copy link
Owner

This pull request:

  • 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:

screenshot from 2018-10-27 19-23-28

All tests produce the expected output.

also adds test examples for each kind of supported variant
@konklone konklone changed the title JSON5 support, and comprehensive examples JSON5 support, and comprehensive tests and examples Oct 27, 2018
@konklone konklone merged commit 85b47a1 into gh-pages Oct 27, 2018
@konklone konklone deleted the use-json5 branch October 27, 2018 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant