How to convert xml response to json in azure apim?

Bhargav Pasarla 120 Reputation points

Need to convert one api response to json from xml response.

Unable to convert xml to json in apim outbound policy.

Methods tried -

var xmlResponse= context.Response.Body.As<String>(preserveContent: true);

--it forms into an encoded string.

var xmlResponse= context.Response.Body.As<XDocument>(preserveContent: true);

--it throws error like it is unable to form xml out of it.

Could you please help if there is any other way?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,750 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 21,091 Reputation points

    @Bhargav Pasarla Thanks for reaching out. To convert an XML response to a JSON response in the outbound policy of your Azure API Management instance, you can use the xml-to-jsonpolicy.

    please refer:

    do let me know incase of further queries, I would be happy to assist you.

    0 comments No comments