Skip to content
Vitaly Tomilov edited this page Dec 29, 2015 · 24 revisions

Why did I write this library?

Initially I needed to remove comments from a JSON file that used open property names, plus regular expressions for values. Such format is known as JSON5.

{
    textValue: 'hello', // comments
    regExValue: /pattern/ // comments
}

My search pointed at two libraries, none of which I found useful in the end:

The first one can only remove comments from a simple-formatted JSON, i.e. JSON5 syntax is out of the question.

The second one relies on regular expressions, which is slow and resource consuming, but the main problem is - its is buggy, and most importantly - it doesn't have any provision for supporting ', " and ` inside regular expressions, breaking those whenever encountered.

And if any such library doesn't come with 100% code coverage, it deserves to be thrown away.

So there I was, writing this simple library that would work in all cases, to be fast and without issues.

I have provided 100% coverage and every test I could think of. And if I missed something - please let me know.

Clone this wiki locally