Skip to content

Inserting in unordered json using a pointer retains the leading slash #2958

@emanuel-raad

Description

@emanuel-raad

What is the issue you have?

Inserting a node in an unordered json object using a pointer retains the leading slash

Please describe the steps to reproduce the issue.

I am using the single json.hpp file

Can you provide a small but working code example?

using json = nlohmann::json;
using ojson = nlohmann::ordered_json;
using json_pointer = nlohmann::json::json_pointer;

std::string p = "/root";

json test1;
test1[json_pointer(p)] = json::object();
std::cout << test1 << '\n';

ojson test2;
test2[json_pointer(p)] = json::object();
std::cout << test2 << '\n';

I also tested with "/root"_json_pointer instead of json_pointer(p) and I get the same behaviour.

What is the expected behavior?

Output from the code above:

{"root":{}}
{"/root":{}}

And what is the actual behavior instead?

I expect both outputs to be the same, without the leading forward slash:

{"root":{}}
{"root":{}}

Which compiler and operating system are you using?

  • Compiler: MSVC\14.28.29910
  • Operating system: Windows 10\19043.1165

Which version of the library did you use?

  • latest release version 3.10.0
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

Not a compilation error.

  • yes
  • no - please copy/paste the error message below

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions