i am consuming wcf service which returns XML response, in Azure APIM i am transforming those into Json response by using the below APIM policy
<xml-to-json kind="direct" apply="always" consider-accept-header="false" />
It works fine until i get xml response as bleow like contains one title in the titles section,
<TitlesResponse>
<Titles>
<Title>
<Name>BookTitle-1</Name>
<Author>BookTitle-2</Author>
</Title>
<Title>
<Name>BookTitle-1</Name>
<Author>BookTitle-2</Author>
</Title>
</Titles>
<Titles>
<Title>
<Name>BookTitle-1</Name>
</Title>
</Titles>
</TitlesResponse>
The json response for the above xml is as below
{
"TitlesResponse": {
"Titles": [
{
"Title": [
{
"Name": "BookTitle-1",
"Author": "BookTitle-2"
},
{
"Name": "BookTitle-1",
"Author": "BookTitle-2"
}
]
},
{
"Title": {
"Name": "BookTitle-1"
}
}
]
}
}
The client expects always Json array in the Title section but it's returning jsonobject when only one title is there.
I tried this in outbound set-body but not working
string xmlContent = context.Response.Body.As<string>(preserveContent: true);
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlContent);
return JsonConvert.SerializeObject(doc);
Do we have any other way to convert to expected Json format from xml in the APIM