xref: /third_party/json/docs/examples/flatten.cpp
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <iomanip>
3c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
4c5f01b2fSopenharmony_ci
5c5f01b2fSopenharmony_ciusing json = nlohmann::json;
6c5f01b2fSopenharmony_ci
7c5f01b2fSopenharmony_ciint main()
8c5f01b2fSopenharmony_ci{
9c5f01b2fSopenharmony_ci    // create JSON value
10c5f01b2fSopenharmony_ci    json j =
11c5f01b2fSopenharmony_ci    {
12c5f01b2fSopenharmony_ci        {"pi", 3.141},
13c5f01b2fSopenharmony_ci        {"happy", true},
14c5f01b2fSopenharmony_ci        {"name", "Niels"},
15c5f01b2fSopenharmony_ci        {"nothing", nullptr},
16c5f01b2fSopenharmony_ci        {
17c5f01b2fSopenharmony_ci            "answer", {
18c5f01b2fSopenharmony_ci                {"everything", 42}
19c5f01b2fSopenharmony_ci            }
20c5f01b2fSopenharmony_ci        },
21c5f01b2fSopenharmony_ci        {"list", {1, 0, 2}},
22c5f01b2fSopenharmony_ci        {
23c5f01b2fSopenharmony_ci            "object", {
24c5f01b2fSopenharmony_ci                {"currency", "USD"},
25c5f01b2fSopenharmony_ci                {"value", 42.99}
26c5f01b2fSopenharmony_ci            }
27c5f01b2fSopenharmony_ci        }
28c5f01b2fSopenharmony_ci    };
29c5f01b2fSopenharmony_ci
30c5f01b2fSopenharmony_ci    // call flatten()
31c5f01b2fSopenharmony_ci    std::cout << std::setw(4) << j.flatten() << '\n';
32c5f01b2fSopenharmony_ci}
33

Indexes created Thu Nov 07 10:32:03 CST 2024