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.
I think as far as other languages are concerned, the best JSON handling gives youn Serde in Rust and F#, from what I read. If only C++ metaprogramming was easier without crazy complexity, Json library would be made to be much smaller and more efficient with less work.
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.
Yeah. It's the custom serialisation & schema/ctor arg validation that makes it clunky.
Yes, though more the other way around: part of json's appeal (on purpose) is that it covers the core subtypes of most dynamically typed programming languages (strings, number, booleans, arrays and maps), so moving data to and from json is straightforward and convenient.
Re:JSON for Modern C++
by StreamBright on Sunday September 29, 2019 @09:54AM
(#21107030)
This is part of it. It is extremly easy to import json and write and read json files and mapping them to Python dicts.
Is that because the python dictionary happens to looks so much like json, or what do they mean?