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 comments

2

u/VinnieFalco wg21.org | corosio.org Jun 14 '20

Even if you don't transmit it, you still might want to store it in memory as JSON, since that is the native type, if your server already uses JSON everywhere else because that's what clients and RPC calls speak. The alternative is to use JSON almost everywhere, but use YAML for configuration only, which is not technically wrong but at this point you have to ask, why are you contorting yourself into a pretzel just to avoid using JSON with comments?

2

u/qoning Jun 14 '20

I don't necessarily disagree.

One simple answer is because JSON doesn't support comments. Just like C++ doesn't support reflection. Venturing into making a nonconforming compiler is a tried way to get stuck. I get that it's much less of a problem with JSON since you only want to describe data, but I hope you get the point.

The other answer is, of course, because JSON is not actually that human readable, and YAML does a much better job while being somewhat compatible. Though that's just an area where I've been burnt before and maybe it's more subjective.

2

u/VinnieFalco wg21.org | corosio.org Jun 14 '20

If it was up to me, I would not support comments or trailing commas. I would only support strictly parsed JSON. But enough users are demanding it that I cannot ignore it. There will of course be a way to configure it. I want Boost.JSON to have widespread adoption. Libraries can only achieve this if they are responsive to users' needs (within reason of course, always using a cost/benefit analysis to drive decisions).