Guide
include
1 |
|
compile with
-std=c++11
CMakeLists.txt
1 | # CMakeLists.txt |
Usage
json demo
1 | { |
with code
1 | // create an empty structure (null) |
serialization
1 | // create object from string literal |
read from file/save to file
1 | // read a JSON file |
Arbitrary types conversions
1 | namespace ns { |
normal method
1 | ns::person p = {"Ned Flanders", "744 Evergreen Terrace", 60}; |
better method
1 | using nlohmann::json; |
That’s all! When calling the json constructor with your type, your custom
to_json
method will be automatically called. Likewise, when callingget<your_type>()
orget_to(your_type&)
, thefrom_json
method will be called.
How do I convert third-party types?
1 | namespace nlohmann { |
How can I use get() for non-default constructible/non-copyable types?
1 | struct move_only_type { |
examples
1 |
|
Binary formats(BSON…)
1 | // create a JSON value |
Reference
History
- 20191012: created.