vivkin / gason

Lightweight and fast JSON parser for C++
MIT License
338 stars 51 forks source link

gason doesn't parse comments #6

Open ChrisJefferson opened 10 years ago

ChrisJefferson commented 10 years ago

I realise that // and /* ... */ comments are both not part of JSON, but they commonly pop up. I feel it it fit's gason's aim to parse as best as possible to handle comments, and they would not hurt efficiency.

I am happy to knock up a patch for this, but wanted to check before I bothered if it would in principle be accepted. I would make no attempt at saving the comments or making them accessable, just skip straight on over them.

vivkin commented 10 years ago

I don't think this is a good idea. Comments are not supported in text editors, other parser and spec. With this extensions writing the simple pretty-print program turned into not a simple task at all.

ChrisJefferson commented 10 years ago

I can understand not wanting to pretty print the comments -- I was suggesting throwing them away entirely.

For my current use, I have written a "strip comments" function I can call on a buffer, which removes comments before I parse the JSON (this function just replaces the comments with spaces, so the buffer becomes valid JSON).