2

I am supposed to unescape an parse this kind of json array of objects

 {
    "httpAlertId": 14,
    "httpAlertName": "raja67",
    "httpUrl": "http://example.com",
    "httpRequestType": "GET",
    "httpHeaders": "sadasdsad",
    "httpVarMap": "{\"Sdsd\":\"dss\"}",
    "httpTimeout": 99,
    "httpRetries": 1,
    "httpCredentials": "{\"username\":\"somename\",\"password\":\"something\"}",
    "mappedAlertActionConfigId": 0
}

What I am expecting is the value of httpCrenentials must become normal JSON.

1 Answer 1

1

var a = {
    "httpAlertId": 14,
    "httpAlertName": "raja67",
    "httpUrl": "http://example.com",
    "httpRequestType": "GET",
    "httpHeaders": "sadasdsad",
    "httpVarMap": "{\"Sdsd\":\"dss\"}",
    "httpTimeout": 99,
    "httpRetries": 1,
    "httpCredentials": "{\"username\":\"somename\",\"password\":\"something\"}",
    "mappedAlertActionConfigId": 0
}

var nJSON = {};
for(key in a){
  var val;
  try{
    nJSON[key] = JSON.parse(a[key]);
  }catch(e){
    nJSON[key] = a[key];
  }
}

console.log(nJSON);

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

3 Comments

How does this answer the question?
Lets say i have array of similar objects, Whats the optimized way to do this for each object?
@LazarLjubenović, I have Interpreted it in wrong. Thanks for pointing.

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.