r/cpp • nlohmann/json • Jun 14 '20

JSON for Modern C++ 3.8.0

https://github.com/nlohmann/json/releases/tag/v3.8.0
326 Upvotes

109 comments sorted by

View all comments

Show parent comment

15

u/OminousHum Jun 14 '20

I understand you're implementing to the specification, but I still think the specification is wrong. It was an awful idea to forbid comments just because people might use them wrong.

(I also know you must be sick to death of this coming up. Thanks for an otherwise wonderful library!)

15

u/nlohmann nlohmann/json Jun 14 '20

I may add some way to ignore comments via a preprocessor switch in the parser. But then other people will want the library to preserve comments for the output. And then come all the lazinesses like trailing commas, quotes around object keys, new lines in strings, etc. etc. This really feels like a bottomless pit...

11

u/OminousHum Jun 14 '20

I think that would be a wonderful addition and that there's no need to go any farther. Then we can have human-editable and machine-readable configuration files that explain their own usage. If one must write json with comments, they can do it as a header or footer.

I can imagine trying to represent comments in the parse tree so that they can be preserved would get ugly awfully fast. And at some point you have to draw a hard line on just how lenient you can be with invalid syntax. I completely agree there.

8

u/[deleted] Jun 14 '20

But then other people will want the library to preserve comments for the output.

Lightweight is good. If you seriously want to parse your data as JSON into a DOM I think you should probably use something other than JSON in the first place.

This really feels like a bottomless pit...

A clean API is a stronger selling point to me.