xref: /third_party/json/docs/examples/unflatten.cpp (revision c5f01b2f)
  • 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_flattened =
11c5f01b2fSopenharmony_ci    {
12c5f01b2fSopenharmony_ci        {"/answer/everything", 42},
13c5f01b2fSopenharmony_ci        {"/happy", true},
14c5f01b2fSopenharmony_ci        {"/list/0", 1},
15c5f01b2fSopenharmony_ci        {"/list/1", 0},
16c5f01b2fSopenharmony_ci        {"/list/2", 2},
17c5f01b2fSopenharmony_ci        {"/name", "Niels"},
18c5f01b2fSopenharmony_ci        {"/nothing", nullptr},
19c5f01b2fSopenharmony_ci        {"/object/currency", "USD"},
20c5f01b2fSopenharmony_ci        {"/object/value", 42.99},
21c5f01b2fSopenharmony_ci        {"/pi", 3.141}
22c5f01b2fSopenharmony_ci    };
23c5f01b2fSopenharmony_ci
24c5f01b2fSopenharmony_ci    // call unflatten()
25c5f01b2fSopenharmony_ci    std::cout << std::setw(4) << j_flattened.unflatten() << '\n';
26c5f01b2fSopenharmony_ci}
27

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