XML to JSON Policy

Not applicable

Hello,

I am trying out the tutorial "Create an API proxy from an OpenAPI Specification" but on adding the XML to JSON policy, I am not getting the desired response. I am still getting the response in XML format. I tried a couple of times but no luck.

0 3 167
3 REPLIES 3

Not applicable

Hello @Chaitanya Sugathan,

I am not sure whats the problem you are getting, but may be the following sample would work for you:

<XMLToJSON name="ABC">
  <Options>
  	<RecognizeNull>true</RecognizeNull>
  </Options>
  <OutputVariable>MYJSON</OutputVariable>
  <Source>MYXML</Source>
</XMLToJSON>

In the above example, the source (MYXML) is an XML object and after converting this to JSON, the MYJSON would be the converted JSON object. So,if you access the MYJSON, you would be able to get the JSON object

Can you please further let me know, whats the issue, in case the the above information is not sufficient?

Content-type header of the source message must be set to application/xml, otherwise the policy is not enforced. Can you please check that?

@Chaitanya Sugathan , I just followed exact instructions & i can see the expected response. Make sure you have attached right policy (XML to JSON) to right flow (GET VIEW XML RESPONSE) at right place (Response) in the flow.