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

Function find overload taking a json_pointer #1017

Closed
markand opened this issue Mar 20, 2018 · 6 comments
Closed

Function find overload taking a json_pointer #1017

markand opened this issue Mar 20, 2018 · 6 comments
Labels
state: please discuss please discuss the issue or vote for your favorite option

Comments

@markand
Copy link

markand commented Mar 20, 2018

Feature Request

It looks like there is no find function taking a json_pointer. I think it could be handy to have a no-throwing find overload for it so we are able to do:

#include <json.hpp>

int main()
{
    auto json = nlohmann::json({
        { "foo", "true" }
    });
    auto it = json.find("/foo"_json_pointer);

    if (it != json.end())
        std::cout << it->dump(4) << std::endl;
    else
        std::cout << "not found" << std::endl;
}
@nlohmann
Copy link
Owner

Internally, JSON pointers are heavily using exceptions internally, so the best such a function would do is, for instance, wrap the existing at function for JSON pointers.

@nlohmann
Copy link
Owner

nlohmann commented Apr 8, 2018

Symmetry-wise, such a find overload could be helpful. Any further thoughts on this?

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Apr 29, 2018
@nlohmann
Copy link
Owner

Any opinions on this?

@nlohmann
Copy link
Owner

No one?

@nlohmann nlohmann added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 27, 2018
@gregmarr
Copy link
Contributor

Is this just another name for at()? Doesn't seem necessary to me, but I don't use json pointers.

@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label May 27, 2018
@madmongo1
Copy link

Sorry for the late comment. This became relevant to me when using your wonderful library in a large production project recently.
Please see the attached bug report.
For my money, I would recommend that either:

  1. find is modified to support json_pointer, or
  2. json_pointer overloads are specifically disallowed (which seems restrictive to me)

At the moment, the API is allowing developers to unwittingly write and compile code that will crash at runtime. I feel this is serious enough to warrant re-opening and addressing this CR.

#1418

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: please discuss please discuss the issue or vote for your favorite option
Projects
None yet
Development

No branches or pull requests

4 participants