Skip to content

Inclusion filtering with Json Path #401

Answered by danielaparker
augustoqm asked this question in Q&A
Discussion options

You must be logged in to vote

If I understand you correctly, perhaps like this?

    json jsonObject = json::parse(R"({"foo":1,"bar":2 })");
    auto inclusionPaths = std::unordered_set<std::string>{"$.foo", "$.baz"};

    std::vector<std::pair<std::string,json>> extractedPathValuePairs;

    auto callback = [&](const std::string& path, const json& val)
    {
        extractedPathValuePairs.emplace_back(path,val);
    };

    for (const std::string& path : inclusionPaths) {
        jsonpath::json_query(jsonObject, path, callback, jsonpath::result_options::path);
    }

    for (const auto& item : extractedPathValuePairs)
    {
        std::cout << item.first << ", " << item.second << "\n";
    }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@augustoqm
Comment options

Answer selected by augustoqm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants