RyanMarcus / dirty-json

A parser for invalid JSON

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

gopalganu opened this issue · comments

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}".'
}

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.

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.

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.

Thanks! I will try the latest version.

That worked. Thanks for quick fixes.