There are already some implementations:
- https://github.com/dharmafly/jsonpatch.js
- https://github.com/stefankoegl/python-json-patch
(I am the author)
Here is slightly cleaner one that I plan to submit as a feature to Backbone. It assumes underscore.js is present: https://github.com/bruth/backbone/commit/a7f8bd3d9fa06a63cf4... Here is a JSFiddle example: http://jsfiddle.net/bruth/pwpNw/ (Open up the console to see the output)
EDIT: Add JSFiddle example for second implementation