Live data from Hacker News

JSON for Modern C++

github.com

11–20 of 125 posts

Re: JSON for Modern C++

#11
post #6

I have been using json11 for a few years now ( https://github.com/dropbox/json11 ). It looks like it has been abandoned though. This seems like a great alternative.

I wouldn't say abandoned, it states in the README:

Maintenance note: This repo is stable but no longer actively maintained. No further development is planned, and no new feature PRs will be merged. Bug fixes may be merged on a volunteer basis.

With JSON being an unchanging spec this makes sense.

Re: JSON for Modern C++

#12

How does this compare with RapidJSON, JSONCpp and JSON Spirit - other popular C++ JSON parser libraries? Links: http://rapidjson.org/ https://github.com/Tencent/rapidjson https://github.com/open-source-parsers/jsoncpp https://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-J...

On the other hand, nlohmann/json has a cleaner and more Python-like API, so if you don't care about performance that much, I'd say it's the way to go

Re: JSON for Modern C++

#13

Kudos on the very thorough readme, complete with CMake instructions, most of the time people take it for granted that you know how to embed libraries and dependencies. Writing documentation, and easing users into your project, is an underrated skill.

Actually, a detailed documentation belongs in a Wiki or a separate markdown document, that README.md is a bit much...

The wiki is a GitHub thing and will not be included in your git clone.

I personally prefer a doc/ folder with RST files in it. That's what the Linux kernel does.

Re: JSON for Modern C++

#14

Kudos on the very thorough readme, complete with CMake instructions, most of the time people take it for granted that you know how to embed libraries and dependencies. Writing documentation, and easing users into your project, is an underrated skill.

The fact that instructions are even required shows how poor the state of c++ packaging is.

Re: JSON for Modern C++

#15

> In languages such as Python, JSON feels like a first class data type. Is that because the python dictionary happens to looks so much like json, or what do they mean?

I lost my mind at this sentence. If feels like a first-class data type because the result of parsing is one of the built-in data types (which can be round-tripped to a similar JSON string). And as soon as you care about serialisation of types it starts feeling incredibly clunky.

Re: JSON for Modern C++

#16
My only mild complaint with this particular JSON library is that it's fairly easy to shoot yourself in the foot with the compile times if you don't explicitly ensure that you use the json_fwd.hpp header in your headers.

Re: JSON for Modern C++

#17

> In languages such as Python, JSON feels like a first class data type. Is that because the python dictionary happens to looks so much like json, or what do they mean?

I lost my mind at this sentence. If feels like a first-class data type because the result of parsing is one of the built-in data types (which can be round-tripped to a similar JSON string). And as soon as you care about serialisation of types it starts feeling incredibly clunky.

Yeah exactly. The equivalent would be to have a JSON parser in C++ which turns a JSON file/object into a C++ object that is accessed in similar ways to other typical C++ objects. So: {"key": value"} becomes json->key = "value" rather than json["key"]. In this library I feel as if they've used operator overloading to emulate the way JSON is used in other languages, rather than making the JSON feel like a first class C++ citizen so to speak.

Re: JSON for Modern C++

#18
post #14

Kudos on the very thorough readme, complete with CMake instructions, most of the time people take it for granted that you know how to embed libraries and dependencies. Writing documentation, and easing users into your project, is an underrated skill.

The fact that instructions are even required shows how poor the state of c++ packaging is.

No, is not. The instructions are for users of the lib that are not using a package manager. If you are using one, in my case vcpkg, then no special instructions are required.

Re: JSON for Modern C++

#19

> In languages such as Python, JSON feels like a first class data type. Is that because the python dictionary happens to looks so much like json, or what do they mean?

I lost my mind at this sentence. If feels like a first-class data type because the result of parsing is one of the built-in data types (which can be round-tripped to a similar JSON string). And as soon as you care about serialisation of types it starts feeling incredibly clunky.

If you want to convert it to an object, have you tried using dataclasses? I haven't used them much, but last time I tried them they felt much easier than trying to use the native dict/list/str/int/etc. that gets returned by default.

Re: JSON for Modern C++

#20
I don't understand the JSON obsession. JSON as any other file format should be a small detail in any application and require very little plumbing code.

In every application, any dependency to JSON should be minimized, contained and preferably eliminated.

Post reply on HN