Skip to content

How to query in Json #2748

Answered by nlohmann
umardraz asked this question in Q&A
Apr 29, 2021 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

This library does not support that functionality (I think it's call JSON Path).

You would need to live with C++ algorithms. Assuming you parsed the JSON to variable j:

auto it = std..find_if(j["users"].begin(), j["users"].end(), [](const json& el) {
    return el["name"] == "umar";
});

if (it != j["users"].end())
{
    std::cout << (*it)["name"] << "\n";
}

(untested)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@umardraz
Comment options

@nlohmann
Comment options

@umardraz
Comment options

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