Skip to content

Can we have an exists() method? #1471

Description

@p-i-

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions