0

I've a large JSON string describing some data. I'd like to loop through this and replace value of all properties named "Key". How can I achieve this using jQuery or plain Javascript?

3 Answers 3

1
var item = $.parseJson("jsonstring...");
var target = "Key";
for (var k in item) {
  if (item.hasOwnProperty(k) && item[k].hasOwnProperty(target)) {
    item[k][target] = "replacement value"
  }
} 

Or similar, depending on the structure of your JSON. This is assuming it's a list of objects.

Sign up to request clarification or add additional context in comments.

Comments

1
for ( var i in data ) {
    for ( var k in data[i] ) {
        if ( k == 'Key' ) {
            data[i][k] = 'new value';
        }
    }
}

Comments

0

for (property in setJson)

{ if (property != 'Key') //do some think }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.