title: Generate JSON-patch from two objects
body: <p>Given two Javascript objects (<code>A</code> and <code>B</code>), is there a way to generate the <a href="https://www.rfc-editor.org/rfc/rfc6902" rel="nofollow noreferrer">JSON patch</a>, so that when that patch is applied to <code>A</code> it would change the object's properties to that of object <code>B</code>?</p>
  <p>For example, given hypothetical <code>JSONPatch</code> function (perhaps being a function of similar name to one of those linked below), what is desired is the <code>generate_patch</code> function.</p>
  <pre><code>patch = generate_patch(A, B)
  JSONPatch.apply(patch, A)  # modifies A so that it has the same properties as B.
  </code></pre>
  <p>In this question <code>A</code> and <code>B</code> are Javascript objects. A patch created by RFC6902 is JSON that would indicate an array of operations which when applied to <code>A</code> that object would become <code>B</code>. The <code>generate_patch</code> function need not return JSON though, rather for efficiency could return a Javascript object that becomes the RFC6902 JSON-patch document when <code>JSON.stringify</code> is called on it.</p>
  <p>The projects I have found on the topic are:</p>
  <ul>
  <li><a href="https://github.com/bruth/jsonpatch-js" rel="nofollow noreferrer">https://github.com/bruth/jsonpatch-js</a> - only patches (does not generate a patch)</li>
  <li><a href="http://jsonpatchjs.com/" rel="nofollow noreferrer">http://jsonpatchjs.com/</a> - same</li>
  <li><a href="https://github.com/Starcounter-Jack/Fast-JSON-Patch" rel="nofollow noreferrer">https://github.com/Starcounter-Jack/Fast-JSON-Patch</a> - observes an object, does not take two different objects</li>
  </ul>