Json to Xml policy does not preserve case of the values

Nagashree Balasundaram 741 Reputation points
2022-10-18T22:32:47.45+00:00

Json to XML transformation using the default policy does not retain the case of the values in the payload.
lower case boolean values in the payload are converted to upper case.
For eg: "IsEncryptionEnabled": false, in the incoming payload is converted as <IsEncryptionEnabled>False</IsEncryptionEnabled> with the 'F' changed to uppercase.
Is there a way to preserve the case of the values?
The backend applications expect the boolean value to be false in lowercase and errors are seen such as Error in deserializing body of request message ; The string 'False' is not a valid Boolean value.

Here is the policy used:
<json-to-xml apply="always" consider-accept-header="false" parse-date="false" namespace-separator=":" />

incoming jsonpayload and converted XML payload from the APIM trace are as shown below:

{
"source": "set-variable",
"timestamp": "2022-10-18T22:28:07.1616509Z",
"elapsed": "00:00:00.0375891",
"data": {
"message": "Context variable was successfully set.",
"name": "reqBody",
"value": "{\r\n \"DocumentId\": \"85e6d0b7-3133-4429-938d-b095fbb11e20\",\r\n \"ActiveVersion\": 1,\r\n \"Name\": \"OAO 2.0 Flow 1.16.20.pdf\",\r\n \"ExpirationDate\": \"0001-01-01T00:00:00\",\r\n \"Tags\": [],\r\n \"TenantId\": \"40348465-298c-4282-b0c8-9b4f42489d07\",\r\n \"IsDeleted\": false,\r\n \"Status\": \"Uploaded\",\r\n \"LastModified\": \"2022-10-14T17:44:27.8539898Z\",\r\n \"ReferenceId\": \"32411354\",\r\n \"TemplateCode\": \"DefaultStipulation\",\r\n \"ReceivedDate\": \"2022-10-14T17:44:27.8539901Z\",\r\n \"IsAnnotated\": false\r\n}"
}
},
{
"source": "json-to-xml",
"timestamp": "2022-10-18T22:28:07.1616509Z",
"elapsed": "00:00:00.0376710",
"data": "JSON-to-XML policy was applied. Original Content-Length header was updated. Content-Type header was set to 'application/xml'"
},
{
"source": "set-variable",
"timestamp": "2022-10-18T22:28:07.1616509Z",
"elapsed": "00:00:00.0376823",
"data": {
"message": "Expression was successfully evaluated.",
"expression": "context.Request.Body.As<String>(preserveContent: true)",
"value": "<DocumentId>85e6d0b7-3133-4429-938d-b095fbb11e20</DocumentId><ActiveVersion>1</ActiveVersion><Name>OAO 2.0 Flow 1.16.20.pdf</Name><ExpirationDate>0001-01-01T00:00:00</ExpirationDate><Tags /><TenantId>40348465-298c-4282-b0c8-9b4f42489d07</TenantId><IsDeleted>False</IsDeleted><Status>Uploaded</Status><LastModified>2022-10-14T17:44:27.8539898Z</LastModified><ReferenceId>32411354</ReferenceId><TemplateCode>DefaultStipulation</TemplateCode><ReceivedDate>2022-10-14T17:44:27.8539901Z</ReceivedDate><IsAnnotated>False</IsAnnotated>"
}
},

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,447 questions
0 comments No comments
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2022-10-19T21:56:06.963+00:00

    @Nagashree Balasundaram Thank you for reaching out to Microsoft Q&A. Currently, when doing XML conversion, we use Boolean.ToString() which converts the value to "True" or "False". Based on a discussion with our product team, this is per design. You can use find-and-replace policy to change the value like below to produce the expected result.
    Policy snippet:
    <inbound>
    <base />
    <json-to-xml apply="always" consider-accept-header="false" parse-date="false" namespace-separator=":" />
    <find-and-replace from="True" to="true" />
    <find-and-replace from="False" to="false" />
    </inbound>

    Response Payload:
    252040-image.png

    If you like this feature request, please let us know and also submit it in aka.ms/apimwish so that others can upvote it too. I hope this answers your question and feel free to add a comment if you have any other questions. We would be happy to assist you.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.