I have json payload in response .
{ "speed":"25.88", "Foo":"Bar", "Latitude":"Something" }
Except: If speed >50 i want to print "speed:""high" or "low". The rest of the data should remain as it is. Kindly someone help me.
Solved! Go to Solution.
Hello Himadri,
You can do this in a JavaScript policy. Something like the below:
var content = context.getVariable("response.content") //read the response content = JSON.parse(content); //parse into an object if (content.speed > 50) { //apply the condition content.speed_class = "high"; } else { content.speed_class = "low"; } context.setVariable("response.content", JSON.stringify(content)); //set it back on the response
Reference: https://docs.apigee.com/api-platform/reference/policies/javascript-policy
Thanks,
Girish
Hello Himadri,
You can do this in a JavaScript policy. Something like the below:
var content = context.getVariable("response.content") //read the response content = JSON.parse(content); //parse into an object if (content.speed > 50) { //apply the condition content.speed_class = "high"; } else { content.speed_class = "low"; } context.setVariable("response.content", JSON.stringify(content)); //set it back on the response
Reference: https://docs.apigee.com/api-platform/reference/policies/javascript-policy
Thanks,
Girish
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |