Skip to content

How To: Query for all values of a given Key within an array #329

Discussion options

You must be logged in to vote

Or using JMESPath:

#include <jsoncons/json.hpp>
#include <jsoncons_ext/jmespath/jmespath.hpp>

using jsoncons::json;
namespace jmespath = jsoncons::jmespath;

int main()
{
    json root = json::parse(R"(
{
    "arr":[
        {
            "keyOfInterest":true,
            "keyOfInsignificants":true
        },
        {
            "keyOfInterest":false,
            "keyOfInsignificants":true
        },
        {
            "keyOfInterest":true,
            "keyOfInsignificants":true
        }
    ]
}
)");

    try
    {
        auto result1 = jmespath::search(root, "arr[*].\"keyOfInterest\"");
        std::cout << "(1) " << result1 << "\n";
        auto result2 = jmespath::search(root, "a…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by RobertLbebber
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