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

Weird behaviour of contains with json_pointer #1815

Closed
kpeeters opened this issue Oct 27, 2019 · 2 comments
Closed

Weird behaviour of contains with json_pointer #1815

kpeeters opened this issue Oct 27, 2019 · 2 comments
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@kpeeters
Copy link

The following code tests the presence of a particular attribute using a json pointer, in two different ways. It prints '1' for the first (which is correct), but '0' for the second line.

#include "json.hpp"
#include <fstream>
#include <iostream>

int main(int, char **)
    {
    nlohmann::json j = {
        {"pi", 3.141},
        {"happy", true},
        {"name", "Niels"},
        {"nothing", nullptr},
        {"answer", {
               {"everything", 42}
        }}
    };

    nlohmann::json::json_pointer ptr("/name");
    std::cout << j.contains( nlohmann::json::json_pointer("/name") ) << std::endl;
    std::cout << j.contains( ptr ) << std::endl;
    }

Any ideas? I would have guessed these are equivalent, but obviously they are not. Tested with g++ 7.4 and clang++ 8.0 using json.hpp 3.7.0.

@nlohmann
Copy link
Owner

Should be fixed in develop branch. Can you please check?

@kpeeters
Copy link
Author

That indeed fixes it, sorry for the bandwidth.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants