vaidik / commentjson

Add JavaScript or Python style comments in JSON.
MIT License
104 stars 25 forks source link

'//' in string still broken in version 0.6 #16

Closed jeremysalwen closed 5 years ago

jeremysalwen commented 7 years ago

How to reproduce this bug:

commentjson.loads(commentjson.dumps('//'))

mewalig commented 5 years ago

The fundamental problem is that this library tries to use regex to strip comments, which can't be done (at least, not in a way that will properly handle all cases). It needs a proper parser to do this. After this discovery, I've decided instead to handle the problem by making a simple system call to a better json comment stripping executable-- there are many available such as https://github.com/douglascrockford/JSMin or https://github.com/sindresorhus/strip-json-comments-- and which took 13 lines of python to replace commentjson

vaidik commented 5 years ago

Yeah you are right. The right way to do this would be to build a parser for the features that commentjson provides. I have not been able to find enough time to do it.

For the solution that you have provided to get around this problem, that might just work if your need is to javascript style comments (if my understanding is correct).

vaidik commented 5 years ago

This is fixed. You can try the latest version of commentjson which addresses this and a lot of other unhandled cases like this.