RyanMarcus / dirty-json

A parser for invalid JSON
GNU Affero General Public License v3.0
294 stars 30 forks source link

Escaped characters and {} in strings seems to cause issue. #3

Closed gopalganu closed 7 years ago

gopalganu commented 7 years ago

This is not supported as it seems to have issue with '{}' inside the quoted string. { "action": "This text is not supported as there it doesn't seem to like curly braces \"${blah}\" \"${blahblah}\"." }

If I enclose the value in single quotes it still doesn't seem to like it, It doesn't seem to handle escaped quote. (doesn\'t) { "action": 'This text is not supported as there it doesn\'t seem to like curly braces \"${blah}\" \"${blahblah}\".' }

RyanMarcus commented 7 years ago

Ah. Yeah, this might be a really fundamental problem with my lexer, since I'm not grabbing entire quoted sequences (since invalid JSON might not have them). I think I need to vastly expand my valid JSON tests. They don't seem at all comprehensive.

RyanMarcus commented 7 years ago

Thinking more about it, the library should probably just attempt to parse the JSON as valid JSON first, and then only use the custom parser if that fails. The custom parser should still work on all valid JSON, but at least this will prevent valid JSON from being rejected.

RyanMarcus commented 7 years ago

Ok, this should be fixed now in NPM version 0.3.2. The problem was actually failing to handle the escaped characters. I've added tests for it.

I also modified the parser code so that if the custom parser fails, it tries the normal JSON parser. If the normal JSON parser works, it returns the valid JSON and prints a warning message. This should ensure the parser never "fails" on valid JSON.

gopalganu commented 7 years ago

Thanks! I will try the latest version.

gopalganu commented 7 years ago

That worked. Thanks for quick fixes.