JSON to XML not working

I have a JSON response from the backend service. I want to convert it to XML.

I have used below code in the Target Endpoint Postflow

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML continueOnError="false" enabled="true" name="JSON-to-XML-1" async="false">
  <DisplayName>JSON to XML-1</DisplayName>
  <OutputVariable>response</OutputVariable>
  <Source>response</Source>
</JSONToXML>

 

This is not giving me the XML output.

Solved Solved
0 1 216
1 ACCEPTED SOLUTION

That's frustrating.

I just tried this and it's working for me. I attached my JSONToXML policy to the target postflow. Please find attached an example working API proxy.

Here's a sample request that shows it working:

 

curl -i ${apigeeendpoint}/j2x-response/t1 

 

Keep in mind that the JSONToXML policy will not transform JSON to XML if the content-type header on the response is not "application/json" or similar.

So if the example I provided here does not help, then... check the content-type header on the response you are trying to transform. If the target sends back json and does not set that header, the target system is might be incorrect! But you can hack Apigee to work around such problems by using an AssignMessage policy to forcibly set the header, prior to invoking JSONToXML. Like this:

 

<AssignMessage name='AM-Override-Ctype-Header'>
  <Set>
    <Headers>
      <Header name='content-type'>application/json</Header>
    </Headers>
  </Set>
</AssignMessage>

 

View solution in original post

1 REPLY 1

That's frustrating.

I just tried this and it's working for me. I attached my JSONToXML policy to the target postflow. Please find attached an example working API proxy.

Here's a sample request that shows it working:

 

curl -i ${apigeeendpoint}/j2x-response/t1 

 

Keep in mind that the JSONToXML policy will not transform JSON to XML if the content-type header on the response is not "application/json" or similar.

So if the example I provided here does not help, then... check the content-type header on the response you are trying to transform. If the target sends back json and does not set that header, the target system is might be incorrect! But you can hack Apigee to work around such problems by using an AssignMessage policy to forcibly set the header, prior to invoking JSONToXML. Like this:

 

<AssignMessage name='AM-Override-Ctype-Header'>
  <Set>
    <Headers>
      <Header name='content-type'>application/json</Header>
    </Headers>
  </Set>
</AssignMessage>