4 ms·
> 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 th
by wodenokoto 7y ago
> 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?
- gsaga 7y agoYeah, that's probably what they meant.
- masklinn 7y agoYes, 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.
- falsedan 7y agoI 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.
- Thorentis 7y agoYeah 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.
- Merg 7y agoI 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.
- onei 7y agoIf 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.
- falsedan 7y agoYeah. It's the custom serialisation & schema/ctor arg validation that makes it clunky.
- StreamBright 7y agoThis is part of it. It is extremly easy to import json and write and read json files and mapping them to Python dicts.