Live data from Hacker News

JSON Patch – a format for describing changes to a JSON document

jsonpatch.com

61–70 of 112 posts

Re: JSON Patch – a format for describing changes to a JSON document

#61
post #52

Earlier quoted context omitted.

> Errr, to apply any delta, including these, you need the document on hand. If your goal is to store deltas, this is no better than anything else. Doesn't this allow the sender to send updates without knowledge of the existing values, though? With a string diff, the existing value would have to be known. > This is in no way better at handling concurrent changes than anything other diff format. In fact, the extra oper…

> Doesn't this allow the sender to send updates without knowledge of the existing values, though? This system requires knowledge of existing values/nodes to create the diff/patch document. However for JSON data, it does have the advantage of not clobbering data unlike a string diff as you mentioned.

You can know keys/paths but nothing else. Or you might have user-specific parts that won't be concurrently modified, but the base JSON doc might be modified by others. You'd have to have the latest version to do a text-based patch.

A text-based diff doesn't really gain much for what it loses in use cases.

Re: JSON Patch – a format for describing changes to a JSON document

#62
post #7

We (Empirical) have implemented a similar couple years ago in our json-backed model. I see two big problems with this standard: 1. Why express paths as a string if you have the ability to encode it as an array in json? Otherwise you run up against the escaping problem for which they use ~0 and ~1 (of all things?!) which is only going to cause bugs. 2. Indexing into arrays is a problem in distributed computing because…

The paths are a standard

I'm pointing out flaws in the "standard."

Re: JSON Patch – a format for describing changes to a JSON document

#63

Earlier quoted context omitted.

I definitely agree that it's a bit too clunky. I think it's arguable though that PATCH itself isn't quite RESTful as it doesn't describe the state of a resource at the identifier, but instead some subset of the state of that resource. Doing that kind of destroys the semantics of the resource identifier. You'd probably still find me arguing for PATCH as it's obviously preferable not to resend an entire resource to ref…

Hmm, I got the impression that REST purists insist on using PATCH. Rails 4 uses it for their REST implementation, for example. Also check out Will Durand's post [1]. I mused about the relative merits of PATCH vs POST in a blog post [2] - if you have any references you wouldn't mind leaving in the comments, I'd love to check them out. PS. nesting resources is a pretty interesting issue in itself; there seem to be a fe…

It's more complex than that: http://roy.gbiv.com/untangled/2009/it-is-okay-to-use-post

Re: JSON Patch – a format for describing changes to a JSON document

#64

Earlier quoted context omitted.

A simple example: if the order of the keys is different, say because of a different json implementation, semantically the document is identical, but you can't apply the patch anymore.

That's why you use a canonicalizing JSON serializer, which you'd also want to use if you were tracking changes to JSON in git, for example.

That's very limiting. So I'm suppose to use the same Json library on various platforms for client as well as server? And what have you really gained?

Re: JSON Patch – a format for describing changes to a JSON document

#65

Earlier quoted context omitted.

A simple example: if the order of the keys is different, say because of a different json implementation, semantically the document is identical, but you can't apply the patch anymore.

That's why you use a canonicalizing JSON serializer, which you'd also want to use if you were tracking changes to JSON in git, for example.

The OP was talking about the current incumbent, and the solution proposed does not work for web applications, since the JSON.stringify in most browsers do not sort keys. Sure, you could implement your own javascript version, but it will be at least a couple of orders of magnitude slower.

Re: JSON Patch – a format for describing changes to a JSON document

#66
post #59

https://www.npmjs.org/package/json-diff-patch

I've just used this to get a solid undo/redo in our WebGL editor. It works amazingly well, and is very performant. However, our backend is not in Javascript, so if I'd want to use it for data transport I'd have to make a compatible python implementation. So I get the point of a standard, so long as it's up to par.

Re: JSON Patch – a format for describing changes to a JSON document

#67

Having the paths in ever operation seems needlessly verbose. If I had an object { id name, password, email, phone } And I wanted to replace the email and phone items would I need to go: {"op": "replace", "path": "/user/0/email", "value": "new@email.address"} {"op": "replace", "path": "/user/0/phone", "value": "+64 4 555 5555"} If I have big objects then that is going to be allot of information to transport, something…

Why? A compression algorithm will remove that verbosity better than a more complex format will. Just use gzip on your HTTP and you're done.

Re: JSON Patch – a format for describing changes to a JSON document

#69
Relatedly, Mattt Thompson of Gowalla/Heroku/Panic/AFNetworking fame proposed Rocket, a technique that pairs JSON Patch and Server-Sent Events to aid in the construction of realtime apps via REST services. The proposal has seemingly been abandon, which is unfortunate as the formalization of handling was interesting, even if one implemented it on top of a different transport layer like Web Sockets or a push notification service.

http://rocket.github.io/

Re: JSON Patch – a format for describing changes to a JSON document

#70

Having the paths in ever operation seems needlessly verbose. If I had an object { id name, password, email, phone } And I wanted to replace the email and phone items would I need to go: {"op": "replace", "path": "/user/0/email", "value": "new@email.address"} {"op": "replace", "path": "/user/0/phone", "value": "+64 4 555 5555"} If I have big objects then that is going to be allot of information to transport, something…

Why? A compression algorithm will remove that verbosity better than a more complex format will. Just use gzip on your HTTP and you're done.

It sort of depends, but it might be more human readable that way. Vs. a bunch of top level operations you have a harder time mentally applying
Post reply on HN