How to convert xml response to json in azure apim?

Bhargav Pasarla 120 Reputation points
2024-03-25T13:36:35.74+00:00

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,751 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 21,171 Reputation points
    2024-03-26T19:15:47.35+00:00

    @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: https://learn.microsoft.com/en-us/azure/api-management/xml-to-json-policy

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

    0 comments No comments