Go to the documentation of this file.00001 #include <json.hpp>
00002
00003 using json = nlohmann::json;
00004
00005 int main()
00006 {
00007
00008 std::string 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 // parse and serialize JSON
00026 json j_complete = json::parse(text);
00027 std::cout << std::setw(4) << j_complete << "\n\n";
00028
00029
00030 // define parser callback
00031 json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
00032 {
00033 // skip object elements with key "Thumbnail"
00034 if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
00035 {
00036 return false;
00037 }
00038 else
00039 {
00040 return true;
00041 }
00042 };
00043
00044 // parse (with callback) and serialize JSON
00045 json j_filtered = json::parse(text, cb);
00046 std::cout << std::setw(4) << j_filtered << '\n';
00047 }