AnsweredAssumed Answered

How to manipulate JSON response payload to modify/add/delete fields?

Question asked by votron on Feb 21, 2017
Latest reply on Feb 21, 2017 by dasjo02

Is there a policy assertion or technique I can use efficiently to manipulate (modify existing attributes, or add/delete attributes) JSON response data to give back to the requestor?  

 

Given:

 

original response:
{

  "name": "First Last",

  "address": "123 Address Dr, Paris, TX",

  "social": "123-45-6789"

}

 

Desired:

updated response - modify existing attribute:

{

  "name": "First Last",

  "address": "123 Address Dr, Paris, TX",

  "social": "***********"

}

 

updated response - add:

{

  "name": "First Last",

  "address": "123 Address Dr, Paris, TX",

  "social": "123-45-6789",

  "new_attribute": "my new value"

}

 

updated response - delete:

{

  "name": "First Last",

  "address": "123 Address Dr, Paris, TX"

}

 

I've looked at the JSONParse and the XMLParse assertions but they are used to convert from XML to JSON and vice versa.  We also looked at policies where u could extract key values out of the JSON response to set as a value.  Is there a way other than having to reconstruct the JSON response attribute-by-attribute to create any of the desired responses?

 

Thanks,

Hoang

Outcomes