title: Find and update in nested json object without changing the same key-pair value in different child path
body: <p>This is an update to my previous question <a href="https://stackoverflow.com/questions/17988939/find-and-update-in-nested-json-object/17991517">Find and update in nested json object</a></p>
  
  <p>Sample Data</p>
  
  <pre><code>TestObj = {
      "Categories": [{
          "Products": [{
              "id": "a01",
              "name": "Pine",
              "description": "Short description of pine."
          },
          {
              "id": "a02",
              "name": "Pine",
              "description": "Short description of pine."
          },
          {
              "id": "a03",
              "name": "Poplar",
              "description": "Short description of poplar."
          }],
          "id": "A",
          "title": "Cheap",
          "description": "Short description of category A."
      },
      {
          "Product": [{
              "id": "b01",
              "name": "Maple",
              "description": "Short description of maple."
          },
          {
              "id": "b02",
              "name": "Oak",
              "description": "Short description of oak."
          },
          {
              "id": "b03",
              "name": "Bamboo",
              "description": "Short description of bamboo."
          }],
          "id": "B",
          "title": "Moderate",
          "description": "Short description of category B."
      }]
  };
  </code></pre>
  
  <p>My Function</p>
  
  <pre><code>function getObjects(obj, key, val, newVal) {
      var newValue = newVal;
      var objects = [];
      for (var i in obj) {
          if (!obj.hasOwnProperty(i)) continue;
          if (typeof obj[i] == 'object') {
              objects = objects.concat(getObjects(obj[i], key, val, newValue));
          } else if (i == key &amp;&amp; obj[key] == val) {
              obj[key] = newValue;
          }
      }
      return obj;
  }
  </code></pre>
  
  <p>called as</p>
  
  <pre><code>getObjects(TestObj, 'id', 'A', 'B');
  </code></pre>
  
  <p>It works fine if I'm going to update id; since id don't have duplicates. But if I'm updating name all data matching key value pair is updated. But how to constrain it into a particular key-pair value.</p>
  
  <p>What shall i provide to the function to constrain the update scope and how to implement it. Please help me.</p>
  
  <p><strong><em>Note:</strong> The json that I will b manipulating will be dynamically generated so I can't have any hard coded value in the function</em></p>