You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The patch { "op": "remove", "path": "" } is currently undefined.
I believe it should have the same result as { "op": "add", "path": "", "value": null }. As a side-result, it would also validate the definition of { "op": "replace", "path": "", "value": null }, which states:
This operation is functionally identical to a "remove" operation for
a value, followed immediately by an "add" operation at the same
location with the replacement value.
In any case, it would benefit from being specified. Some implementations currently throw, and that is unfortunate, as it breaks the specification as quoted above..
I disagree with the solution. I think { "op": "remove", "path": "" } should be an error. If you want to replace the root element, you can already use { "op": "add", "path": "", "value": null } today. Even that is strange.
It could be reasonable to allow the replace to work with an empty path to replace the element completely, and, compatibility aside, disallow add to do the same. This would provide the most intuitive semantics. add and remove require a non-empty path, replace is able to replace the root.
But since we most likely want to be compatible, I think add should stay as it is, replace should explicitly allow to replace the root and remove on the root should be an error.
Activity
Test the removal of the whole document
d-frey commentedon Sep 2, 2016
I disagree with the solution. I think
{ "op": "remove", "path": "" }should be an error. If you want to replace the root element, you can already use{ "op": "add", "path": "", "value": null }today. Even that is strange.It could be reasonable to allow the
replaceto work with an empty path to replace the element completely, and, compatibility aside, disallowaddto do the same. This would provide the most intuitive semantics.addandremoverequire a non-empty path,replaceis able to replace the root.But since we most likely want to be compatible, I think
addshould stay as it is,replaceshould explicitly allow to replace the root andremoveon the root should be an error.espadrine commentedon Nov 13, 2016
What matters most is that the undefined behavior gets specified.
That being said, if we go with your solution, we lose the functional equivalence of
replacetoremove+add, which will be a bit counterintuitive.