I have a very large JSON string that I need to parse with in-browser JavaScript. Right now, in a few browsers, I run out of stack space. Unfortunately, my JSON can contain user strings, so I can’t use eval or otherwise let the browser parse it.
I’ve looked at a few of the standard JavaScript JSON parsers, and they are recursive. Wondering if anyone knows of any JSON parser that is safe and non-recursive. I’d be willing for it to have fewer features — I just have a giant array of objects.
Alternatively, if someone knows of one that might be easy to modify, that would be a big help too.
EDIT: On closer inspection the stack overflow is thrown by eval() used inside the parser. So, it must be recursive.
JSON parsing in browser is usually done with just eval, but preceding the eval with a regular expression “lint”, that is supposed to make it safe to evaluate the JSON.
There is an example on this on wikipedia: