Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add count member function #45

Closed
gnzlbg opened this issue Mar 10, 2015 · 0 comments
Closed

Add count member function #45

gnzlbg opened this issue Mar 10, 2015 · 0 comments

Comments

@gnzlbg
Copy link

gnzlbg commented Mar 10, 2015

A typical operation is to find if a json object has a given key, this is typically done like:

json j;
bool has_key = j.find("key") != j.end();

The standard containers (std::map, std::set,...) offer a count member function that counts the number of occurrences of a key, such that one can:

std::map<std::string, int> m;
bool has_key = m.count("key");  // -> count == 0? false : true

It would be nice to have something similar since this is a very common operation.

@nlohmann nlohmann self-assigned this Mar 22, 2015
GerHobbelt pushed a commit to GerHobbelt/nlohmann-json that referenced this issue May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants