4 ms·
I used to do it a similar way, but often I ended up copying everything up to the final `}` character (or sometimes the input has single-quote characters rather
by crabl 8y ago
I used to do it a similar way, but often I ended up copying everything up to the final `}` character (or sometimes the input has single-quote characters rather than double-quotes), which causes the JSON to be invalid. NiceJSON takes the input (even if it's malformed), attempts to construct an abstract syntax tree using json-ast[0] and then serializes the output (which should be well-formed JSON).
[0]: https://www.npmjs.com/package/json-ast https://www.npmjs.com/package/json-ast