Skip to content

json::contains usage to find a path #1727

Description

@devhandle
  • Describe what you want to achieve.

I want to test whether a path exists in a json file. For example, "/root/settings/logging".

  • Describe what you've tried.
auto jPtr = json::json_pointer("/root/settings/logging"_json_pointer);
auto exists1 = jsonfile.contains(jPtr);

auto exists2 = jsonfile.contains(json::json_pointer("/root/settings/logging"_json_pointer));

exists1 is false and exists2 is true.

I expected both of these to be true. Is this a bug or is this expected behaviour?

UPDATE: There are two contains functions. One which takes an rvalue reference to a KeyT and one which takes a reference to a json_pointer. Both do different things. This seems inconsistent to me. If I std::move jPtr it works but I don't want to move the pointer.

  • Describe which system (OS, compiler) you are using.

g++ (Ubuntu 8.3.0-6ubuntu1~18.10.1) 8.3.0

  • Describe which version of the library you are using (release version, develop branch).

v3.7.0

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions