Skip to content

Delete by json_pointer #1248

@SimonEbner

Description

@SimonEbner
  • Describe the feature in as much detail as possible.
    Use json_pointer for erasing keys from json

  • Include sample usage where appropriate.

#include "nlohmann/json.hpp"
#include <iostream>

int main() {
    auto j = R"({"x": {"y": 1}})"_json;
    nlohmann::json::json_pointer ptr("/x/y");

    std::cout << "Delete by ptr: " << j.erase(ptr) << std::endl;
    std::cout << "j: " << j << std::endl;
}

Actual output:

Delete by ptr: 0
j: {"x":{"y":1}}

Expected output:

Delete by ptr: 1
j: {"x":{}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: enhancement/improvementstate: please discussplease discuss the issue or vote for your favorite optionstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions