Closed brandom closed 10 years ago
Hi @brandom,
I'm afraid I can't merge this because it brakes quite easily (e.g. 'a: "b: c"' breaks).
Thanks for submitting your PR anyways
@federomero Like I said in the comments, it makes a best effort to convert invalid JSON into valid JSON before JSON.parse(). I wouldn't say it breaks because the string above would not have been parsed either way. The regex is only applied to invalid JSON and the original string is returned if the result cannot be parsed, just like the existing code.
My regex skills are lacking so I am sure this can be improved, but it doesn't break the existing functionality of prettifying valid JSON.
This is a best effort approach using regular expressions. There may be a mature lib or better way to do this, but this will work in most cases.