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

Several issues #28

Open
lazytyper opened this issue Oct 13, 2021 · 3 comments
Open

Several issues #28

lazytyper opened this issue Oct 13, 2021 · 3 comments

Comments

@lazytyper
Copy link

I've been testing jsonic for a few minutes and discovered several issues:

  1. JSON file can contain just a number or string:
JSON.parse('0')
// -> 0
JSON.parse('"a string"')
// -> 'a string'

jsonic cannot parse this, but should be compatible to JSON.

  1. Hexadecimal number support ?
{ 0x12: 0x14 }
// -> { '18': 20 }
jsonic('{0x12:0x14}')
{ '0x12': '0x14' }

The result is not what I expected (same result as in JS). Hexadecimal numbers could be supported.
And invalid numbers like 0g12 could cause a parse error.

  1. Strings without quote

I don't really like that way string don't require quotes. It can confuse and it's not much work to add two quotes.

Example:

var name = 'John Doe';
var o = { name: name }

I don't need to tell what the result of js and jsonic is.
And { name: John Joe } is not even valid JS.
Better: disable that by default, and require quotes.
If the programmer badly wants the short syntax, it could be turned on optionally.

@lazytyper
Copy link
Author

I already found a similar parser which seems to be perfect:
It parses "just a number/string" correctly, supports hex codes and it doesn't support exotic syntaxes.

@rjrodger
Copy link
Collaborator

@lazytyper actually in the middle of a big rewrite to address those issues! :)
Which parser did you choose?

@lazytyper
Copy link
Author

It's json5 (www.json5.org).

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

No branches or pull requests

2 participants