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

Applying JSON patch creates parent object #3134

Closed
chainwheel opened this issue Nov 11, 2021 · 1 comment · Fixed by #3628
Closed

Applying JSON patch creates parent object #3134

chainwheel opened this issue Nov 11, 2021 · 1 comment · Fixed by #3628
Assignees
Labels
confirmed kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@chainwheel
Copy link

Running the following function

void test_prob() {
    auto doc = R"(
        {
            "a": {}
        }
    )"_json;

    auto patch = R"(
        [
            {
                "op": "add",
                "path": "/a/b/c/d",
                "value": 1
            }
        ]
    )"_json;

    auto doc1 = doc.patch(patch);
    auto d = doc1.dump(2);
    printf("%s\n", d.c_str());
}

results in creating b and c parent objects:

{
  "a": {
    "b": {
      "c": {
        "d": 1
      }
    }
  }
}

while according to RFC6902 it is an error:

"Because this operation is designed to add to existing objects and
arrays, its target location will often not exist. Although the
pointer's error handling algorithm will thus be invoked, this
specification defines the error handling behavior for "add" pointers
to ignore that error and add the value as specified.

However, the object itself or an array containing it does need to
exist, and it remains an error for that not to be the case.
"

BTW, great library, thank you very much!

@Hudson00
Copy link
Contributor

I've issue a pull request to address this issue here.

@nlohmann nlohmann linked a pull request Dec 28, 2021 that will close this issue
falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Jul 29, 2022
falbrechtskirchinger pushed a commit to falbrechtskirchinger/json that referenced this issue Jul 29, 2022
The previous behavior was not in accordance with RFC6902.
Add unit test.

Fixes nlohmann#3134.
falbrechtskirchinger pushed a commit to falbrechtskirchinger/json that referenced this issue Jul 29, 2022
The previous behavior was not in accordance with RFC6902.
Add unit test.

Fixes nlohmann#3134.
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation release item: 🐛 bug fix labels Jul 30, 2022
@nlohmann nlohmann self-assigned this Jul 30, 2022
@nlohmann nlohmann added this to the Release 3.11.0 milestone Jul 30, 2022
nlohmann pushed a commit that referenced this issue Jul 30, 2022
* Fix patch::add creating nonexistent parents

The previous behavior was not in accordance with RFC6902.
Add unit test.

Fixes #3134.

* Fix incorrect JSON patch unit test

Co-authored-by: Hudson00 <yagdhscdasg@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
3 participants