json-patch/json-patch-tests

should change `add` to `replace`?

Alanscut opened this issue · 1 comments

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": {} },

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