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

should change add to replace? #44

Open
Alanscut opened this issue May 23, 2020 · 1 comment
Open

should change add to replace? #44

Alanscut opened this issue May 23, 2020 · 1 comment

Comments

@Alanscut
Copy link

when I run the follow case with python-json-patch, it failed. Detail in stefankoegl/python-json-patch#111 (comment). But when I change the add operation to replace, it succeeded.

{ "comment": "replace array document with object document?",
"doc": [],
"patch": [{"op": "add", "path": "", "value": {}}],
"expected": {} },

@jayvdb
Copy link

jayvdb commented Aug 15, 2023

A path of "" means the root, or whole document.
See https://datatracker.ietf.org/doc/html/rfc6901#section-5

"" // the whole document

The fact "add" to the whole document does a replace is covered by this part of the json-patch spec

https://datatracker.ietf.org/doc/html/rfc6902/#section-4.1

If the target location specifies an object member that does exist, that member's value is replaced.

The root exists, so it becomes a replace op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants