What's wrong with writing "initializers" which are serializers/deserializers? If you're looking for automatic file format to C++ class object, why settle for JSON (whether it's this library or JSONCpp) why not use Thrift or Protocol Buffers?
- Thrift: https://thrift.apache.org/ - Protocol Buffers: https://developers.google.com/protocol-buffers/
Because I'm not writing code in a vacuum, and JSON is what everyone else is using. JSON is chosen for simplicity & interoperability.
Maybe JSON is what you get sent and you've got no control over that? Or JSON is what you want to expose and you've got no control over that either? You can want to achieve reasonable performance while still meeting external requirements.
This has carried me for 99% of all use cases along with a try/catch that barfs and an array specialization that makes a vector:
template<typename T> T get(const char* key) { return boost::lexical_cast<T>( json.GetObject(key) ); }
The reality is that if I see some value of a type I wasn't expecting, something probably went wrong or changed in the protocol anyways.
The idea that types can replace code is just broken. The type system is not a programming language. Or at least, as proven by C++/Haskell/..., not a remotely usable one.
It's obviously not simple - no two parsers have the same behaviour!
To be clear, I was not talking about lexing JSON, but about how to configure a "meta-parser" like this library to actually convert some JSON to concrete application data objects. The point of contention was, "should we really use such a massive library or mustn't it be sufficient to have a simple bag of parsing primitives (which we can use to actually build the right thing)".
And I'm not a fan of JSON either...
> Tip, if you want to defeat an argument by quoting only three words, make sure you're talking about the same thing.
Please don't be snarky - if you disagree say so and why.
My apologies. Just did that - I'm habitually a post-then-improve type of commenter.