mirror of
https://github.com/nlohmann/json.git
synced 2026-10-02 12:40:32 +00:00
- API pages for operator[], at, front, back, find, contains, count, begin, end, cbegin, cend, items, and type_name of basic_json_view, linked both ways with the basic_json pages - the feature page and size() describe document order and duplicate keys - the examples show when the view helps: reading a few fields of a large text, probing optional members, and members in source order Signed-off-by: Niels Lohmann <mail@nlohmann.me>
19 lines
677 B
C++
19 lines
677 B
C++
#include <iostream>
|
|
#include <nlohmann/json_view.hpp>
|
|
|
|
using json_document = nlohmann::json_document;
|
|
|
|
int main()
|
|
{
|
|
// a log record: the fields matter in the order they were written, e.g.
|
|
// to reproduce the record as it was logged. A nlohmann::json object
|
|
// sorts its keys, so materializing and iterating it would instead print
|
|
// them alphabetically ("level", "message", "time")
|
|
json_document record = json_document::parse(R"({"time": "10:00:01", "level": "info", "message": "started"})");
|
|
|
|
for (auto it = record.root().begin(); it != record.root().end(); ++it)
|
|
{
|
|
std::cout << it.key() << '=' << it->materialize().dump() << '\n';
|
|
}
|
|
}
|