FindReplace Field

by dshilkret

JavaScript

var myObject = [
  {
    "query": {
      "bool": {
        "must": [
          {
            "term": {
              "Field": "incident.x_150952_cosmos_se_u_url_3"
            }
          },
          {
            "term": {
              "Field": "incident.time_worked"
            }
          }
        ]
      }
    }
  }
];

function findAndReplace(object, value, replacevalue){
  for(var x in object){
    if(typeof object[x] == typeof {}){
      findAndReplace(object[x], value, replacevalue);
    }
    if(object[x] == value){ 
      object["Field"] = replacevalue;
      // break; // uncomment to stop after first replacement
    }
  }
}

findAndReplace(myObject, "incident.x_150952_cosmos_se_u_url_3", "test grp55");
findAndReplace(myObject, "incident.time_worked", "test grp75");

document.body.innerHTML = JSON.stringify(myObject);
console.log(myObject);