-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Can we have an exists() method? #1471
Copy link
Copy link
Closed
Labels
release item: ✨ new featuresolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Milestone
Description
Activity
Metadata
Metadata
Assignees
Labels
release item: ✨ new featuresolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
I wish to determine whether a particular key exists.
This is one of those things it's reasonable to expect, and surprising that there is no easy / obvious / direct solution.
is_null()(rather dangerously IMHO) silently creates the key.https://stackoverflow.com/questions/49850890/c-nlohmann-json-how-to-test-nested-object-is-existent-or-empty suggests
.count()but again is not obvious how to apply this.I've seen other solutions suggested involving iterators.
Pretty sure I saw a nice solution the other day in an issue, but now I can't find it.
Why not simply have an
exists()method?The documentation is super helpful for ENcoding JSON, but lacking in code examples for extracting from JSON.