Javascript JSON comparison/diff?
<p>Say I have the following 2 json objects:</p>

<pre><code>JSON A:
{
"Field A":"1",
"Field B":"2",
"Field D":"Something",
"Field E":"6"
}

JSON B:
{
"Field A":"1",
"Field B":"2",
"Field C":"3",
"Field D":"Different"
}
</code></pre>

<p>Sample Function:
    function (jsonstringA, jsonstringB) </p>

<p>Example (If JSON A and JSON B used as parameters):</p>

<p>Returns a new JSON object containing:</p>

<pre><code>{
"Field C":"3", // because function sees jsonstringB had no "Field C"
"Field D": "Different" // sees jsonstringB had a different value for "Field D"
}
</code></pre>

<p>Note that it is using jsonstringA as the base of the comparison, so the function returns only the fields missing and values of jsonStringB. That is why "Field E" and its value is not returned.</p>

<p>What is the best way if possible to come up with a function that returns a json object containing values that have changed?</p>

<p>WHAT I HAVE TRIED:
I have tried doing a comparison by manually specifying the fields that I am trying to check for, but I would like to have something that requires me to not hardcode the "Fields" as it is very inefficient and everytime I add a new field to JSON B, I have to hardcode in the field I am looking for... that is why I am looking for something less of a pain.</p>
