jsonicjs / jsonic

JSON parser that isn't strict
MIT License
199 stars 23 forks source link

Several issues #28

Open lazytyper opened 3 years ago

lazytyper commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

lazytyper commented 2 years ago

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