//my json data
var jsndata = \"{ \"id\": \"5001\", \"type\": \"None\" },
{ \"id\": \"5002\", \"type\": \"Glazed\" },
{ \"id\": \"5005\",
modified the function from above to be able to change all values of a key,and increment it by 1. And you can pass in the jsonObj
function replaceByValue( jsonObj, field, oldvalue, newvalue ) {
for( var k = 0; k < jsonObj.length; ++k ) {
jsonObj[k][field] = (newvalue *1)+k;
}
return jsonObj;
}
//example
var json = [{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" },
{ "id": "5009", "type": "Juice" }];
json;
replaceByValue( json, "id", "na", 123 );
json;