Why not just send partial fields and handle it server side?
Not to mention its more data over the wire for small changes.
Why not just send partial fields and handle it server side?
Not to mention its more data over the wire for small changes.
You have:
{
"baz": "qux",
"foo": "bar"
}
Then you send the patch: {
"baz": "boo"
}
It's clear you want to change baz value to boo, but did you mean to delete foo or just ignore it? If "ignore", how do you indicate delete? If "delete", you will now have to send the entire JSON every time, anyway, so it's not a patch. Whatever your answers, there, it's not a "why not just..." situation.You have a deeply nested property in a gigantic JSON document that you want to move, "why not just" send
{ "op": "move", "from": "/a/b/c/d", "path": "/a/b/c/e/f" }
To be clear, I have never seen JSON Patch before, either. {
"baz": "boo"
}
DELETE would remove baz, PATCH would change baz, and PUT would, in effect, remove foo.Another option, though, is to use the Range-Patch spec from: https://github.com/braid-org/braid-spec
For example: ElasticSearch can take a body on some GET requests, but many tools will not let you do this because a GET request should not have a body.
Append, insert at, remove, and remove at are more ambiguous.
won't that set a field called 'null', to the value null?
You can interpret a null field the same as a missing field. You only need to worry if you have arbitrary dictionary keys and need to differentiate a null value from an missing key.
Null != missing.
Not in the general case no, they are two different states, which may have entirely different semantics.
For instance a missing field can mean "don't touch this field" while a field set to null means "set this field to null".
Some schemas might opt to ignore this distinction and collapse the states, but that is a specific decision, and an express loss of information.
> You only need to worry if you have arbitrary dictionary keys and need to differentiate a null value from an missing key.
There are other situations where that's an issue, like the above, or when you're using the object as a set (which JSON doesn't have), or when you've defined the schema to never have missing fields (but possibly have some set to `null`) so clients will break, ...
{ "foo": null }
and you delete a field using { "foo": null }
don't you see a bit of an issue there?the partial updates approach works ok for updating 'schemaful' data, where it could only ever mean to set the field to null and could never delete the field from the object altogether
but for editing a JSON document or other schemaless data then both operations are possible and you'd need to be able to distinguish them
I guarantee, another dev would come along, look at the custom spec, and think "Why not just use JSON Patch?"