Go to the documentation of this file.00001 #include <json.hpp>
00002
00003 using json = nlohmann::json;
00004
00005 int main()
00006 {
00007
00008 auto text = R"(
00009 {
00010 "Image": {
00011 "Width": 800,
00012 "Height": 600,
00013 "Title": "View from 15th Floor",
00014 "Thumbnail": {
00015 "Url": "http:
00016 "Height": 125,
00017 "Width": 100
00018 },
00019 "Animated" : false,
00020 "IDs": [116, 943, 234, 38793]
00021 }
00022 }
00023 )";
00024
00025 // fill a stream with JSON text
00026 std::stringstream ss;
00027 ss << text;
00028
00029 // parse and serialize JSON
00030 json j_complete = json::parse(ss);
00031 std::cout << std::setw(4) << j_complete << "\n\n";
00032
00033
00034 // define parser callback
00035 json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
00036 {
00037 // skip object elements with key "Thumbnail"
00038 if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
00039 {
00040 return false;
00041 }
00042 else
00043 {
00044 return true;
00045 }
00046 };
00047
00048 // fill a stream with JSON text
00049 ss.clear();
00050 ss << text;
00051
00052 // parse (with callback) and serialize JSON
00053 json j_filtered = json::parse(ss, cb);
00054 std::cout << std::setw(4) << j_filtered << '\n';
00055 }