Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to modify existing value in Json Payload body passing request.

Not applicable

I have an API proxy and I passing json request in the body of request.

[{"status": "success", "ID":"200","UName":"xxxxx"}] and many more list of array..

I want to change the UName value. How to do it.

Solved Solved
1 3 9,307
1 ACCEPTED SOLUTION

HI @Madhav

Welcome to the community !!!

You can do that using JavaScript policy.

The code is something like:

var body = JSON.parse(request.content);
body.forEach(function(item){
   item.UName = "newValue"; //set value
});
request.content = ''; //To clear the request payload
request.content = JSON.stringify(body);

NOTE: Make sure this policy is within the Request flow of either Proxy or Target end point

Hope this helps !

View solution in original post

3 REPLIES 3