Tuesday, September 8, 2020

SAP API Management - JSON to XML conversion

 Scenario: Target system returns the response in JSON format. But Client wants the response in XML format.

Sample JSON Payload returned from Target:

{"firstName":"John","lastName":"Doe","city":"San Jose","state":"CA"}

Steps:
1. Add an instance of JSONTOXML policy in Response path.


2. Modify the policy as per requirement.

In this case, code is modified as below:

<!-- This policy converts a JSON payload to XML structure -->
<JSONToXML async="true" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Options>
<ObjectRootElementName>root</ObjectRootElementName>
</Options>
<Source>response</Source>

3. Test the API Proxy





1 comment: