phadej / relaxed-json

Relaxed JSON is strict superset JSON, relaxing strictness of vanilla JSON
http://oleg.fi/relaxed-json/
Other
80 stars 8 forks source link

Parse has issues with strings with colon , such as urls #10

Open 0o-de-lally opened 8 years ago

0o-de-lally commented 8 years ago

I really get a lot of use of RJSON thanks for this!

One use case is to convert strings into js types. However there's an edge case when the string contains a colon, such an URL.

I know it's not a typical use of RJSON, but its very helpful for processing query strings in web development. Though if the query string has a URL, it fails.

RJSON( 'a')

'a'

RJSON('http://google.com')

SyntaxError: Unexpected token :

0o-de-lally commented 8 years ago

@phadej any thoughts on this?

phadej commented 8 years ago

"a" is an identifier which is parsed into a string "a". http://google.com is lexically "http": "//google.com".

Those probably aren't real-world-examples, as RJSON('"http://google.com"') as an easy fix, in this case.

It's not trivial to makerelaxed-json smarter, as it relies on lexical analysis (identifies different tokens) first.