Skip to content

Remove item from array based on it's value. #3488

Discussion options

You must be logged in to vote

Try this:

  • Iterate through the array.
  • Find the object where the key "title" has the value "My Game2" and stop iterating.
  • If the iterator is not the past-the-end iterator, erase the object at that location.
auto it = j.begin();
for(; it != j.end(); ++it) {
    if(it->at("title") == "My Game2")
        break;
}

if(it != j.end()) j.erase(it);

https://json.nlohmann.me/api/basic_json/begin/
https://json.nlohmann.me/api/basic_json/at/
https://json.nlohmann.me/api/basic_json/erase/

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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