delete json property from response body

Not applicable

I want to delete the *params* property from the response body. I've tried a javascript callout, but haven't been able to identify the correct variable / syntax to remove it. I also tried assign-message policy but that seemed to only be for headers and query params.

{ "action": "get", "application": "abc", "params": { "client_secret": [ "my_secret" ], "client_id": [ "my_id" ] }, "path": "/parts", "uri": "https://www.google.com", "entities": [ ...]...}

Solved Solved
1 3 2,827
1 ACCEPTED SOLUTION

var r = JSON.parse(context.getVariable('response.content'))
delete r.params
context.setVariable('response.content', JSON.stringify(r))

Give that a try. For better robustness, probably good to throw a hasOwnProperty check in there first.

(This has the precisely correct number of semicolons...)

View solution in original post

3 REPLIES 3

var r = JSON.parse(context.getVariable('response.content'))
delete r.params
context.setVariable('response.content', JSON.stringify(r))

Give that a try. For better robustness, probably good to throw a hasOwnProperty check in there first.

(This has the precisely correct number of semicolons...)

Looks really good, except.... not enough semicolons.

Please add some.

Looks like @jasonbrown is trying to delete from the response body.

You can try using this JS policy on the Response flow

var obj = response.content.asJSON;
if(delete obj.params){
    response.content = '';
    response.headers['Content-Type'] = 'application/json';
    response.content.asJSON = obj;
}