Starcounter-Jack / JSON-Patch

Lean and mean Javascript implementation of the JSON-Patch standard (RFC 6902). Update JSON documents using delta patches.
MIT License
1.81k stars 215 forks source link

How to add or replace in JSON-PATCH #158

Closed johanlelan closed 7 years ago

johanlelan commented 7 years ago

I have a question for the JSON-PATCH developers and users. I have so many clients asking me why "op": "replace" returns a OPERATION_PATH_UNRESOLVABLE on not existing path. Their argument is that JSON-PATCH is used to lower the bandwith. But this need to known the resource before computing "add" or "replace" operation. (ie. send HTTP GET before computing the HTTP PATCH)

It could be reasonably efficient to only send a replace on operation and let the server add the field or replace it. (perhaps creating a new upsert operation??)

What is your opinion or your manner to solve this problem?

johanlelan commented 7 years ago

I found an quite useful answer : https://tools.ietf.org/html/rfc6902#section-4.1

In the RFC, add could be invoke on existing field!!!