Re:What Is JSON Patch?
by salil999 on Tuesday May 10, 2022 @02:08AM
(#31323990)
Where would this be useful? I am not trying to bring the article down but I'm genuinely interested in knowing where/how people would use this. It seems like just locally modifying a payload would be more efficient?
[ Parent
| on HN ]
Re:What Is JSON Patch?
by mathgladiator on Tuesday May 10, 2022 @02:13AM
(#31324015)
JSON merge ( https://datatracker.ietf.org/doc/html/rfc7386 ) is the entire basis for how I persist document changes to disk and to clients ( http://www.adama-platform.com/2021/03/28/json.html ).
Arrays require some care to handle which is why I'm got some extensions in my client, but a super power that JSON patching enables is that it can be algebraic in nature. That it, we can define a patching which is associative (another extension where you preserve nulls) such that (X + da) + db = X + (da + db) = X + dc where da + db + dc
This allows you to leverage flow control when congestion happens (especially on mobile connections).
Using it for k8s currently, in a request like
[{"op": "replace", "path":"/spec/template/metadata/annotations/restarted-at", "value": "'$(date -Iseconds)'"}]
to restart/redeploy.
Amazon uses this for changes to API Gateway. Take that as either a positive or a negative :)
I can think of realtime collaborative document editing - patches are sent to the server instead of sending the whole JSON-based document every time and the app resolves potential conflicts.
But i wonder if you have to use a very long pointer expression to identify a single character being typed, you'd end up with much higher overhead.
Software such as Kubernetes uses it with different processes writing to the same data fields, but different subsets. If you have a typical API with only one main blob that gets updated in its entirety, you might not avoid conflicts using the PATCH approach.
We have a supplier who uses it to distribute daily updates to their (large) product catalog. It helps that most of the mutations are to specific fields like availability and price, while EAN/GTIN etc tend to be stable. Deletions are trivial as well.
Kustomize patches.
Re:What Is JSON Patch?
by EdwardDiego on Tuesday May 10, 2022 @03:10AM
(#31324385)
I've used it with K8s and kustomize a fair bit.