loading...

Discussion on: Forgiving pretty-print

Collapse
eruizdechavez profile image
Erick Ruiz de Chavez

That is most likely impossible. In order to pretty print some JSON value it needs to be valid. Otherwise there is no way to know if something is a key, a value, an array, a string, etc. The try/catch in my example will give you the first error it finds and then you can use that to (eventually) fix the string.

As a last resort, you could code a simple script to insert new lines (and maybe even do some indentation) whenever you see some standard characters like ", : or {.