JSON Patch - a C# implementation
I’m in the process of trying to implement JSON Patch as a way to cut the chatter down between my various home automation systems. In particular, since I’ve implemented a SignalR-all-the-things web interface I want to push updates across to the browser as efficiently as possible. I also want to make communication with mobile devices as efficient as possible.
To this end my home automation server now maintains a state for each mobile device or browser session for all the objects that browser or mobile connection is currently displaying. When things change it filters the changes according to what’s on the display and sends down the full or partial objects accordingly. But now I plan to calculate a set of JSON Patch differences and send them down as things change rather than sending the whole object. This should dramatically reduce how much data is being sent.
To that end I started writing an implementation of JSON Patch tonight. The first part is concerned with calculating a patch as a difference of two objects. Tomorrow night I’ll implement the apply method that applies a patch to an existing object.
Anyway, here’s tonight’s code in case anyone else wants to do this.
Fri May 02 2014 08:05:07 GMT-0700 (Pacific Daylight Time)