1

Sample xml request :

<env:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  <ns5:CreateCustomerProfileRequest>
    <ns5:SourceApplication>
      <ns3:ApplicationID>HYBRIS_01</ns3:ApplicationID>
      <ns3:ApplicationName>Hybris</ns3:ApplicationName>
    </ns5:SourceApplication>
    <ns5:CustomerProfile>
      <ns5:CustomerIdentification>
        <ns5:CustomerIDType>bill-to</ns5:CustomerIDType>
        <ns5:CustomerID>618a18b3f33fa4007f2e76be</ns5:CustomerID>
        <ns5:CustomerNumber/>
      </ns5:CustomerIdentification>
      <ns5:UserId>franlopue@icloud.com</ns5:UserId>
      <ns5:CustomerType>Customer</ns5:CustomerType>
      <ns5:CustomerAddressBook>
        <ns3:Email>
          <ns3:EmailAddress>franlopue@icloud.com</ns3:EmailAddress>
        </ns3:Email>
      </ns5:CustomerAddressBook>
      <ns5:CustomerName>
        <ns3:FirstName>Francisco</ns3:FirstName>
        <ns3:LastName>Lopez-puente</ns3:LastName>
      </ns5:CustomerName>
      <ns5:CustomerSleep>35</ns5:CustomerSleep>
      <ns5:ModifiedByName/>
      <ns5:BillToInd>false</ns5:BillToInd>
      <ns5:ShipToInd>false</ns5:ShipToInd>
    </ns5:CustomerProfile>
  </ns5:CreateCustomerProfileRequest>
</env:Body>

Json :

{"body": {
"ProcessName":"SC Account Registration Process",
            "SiebelMessage": {
            "IntObjectName": "SC EAI Contact",
            "MessageType": "Integration Object",
            "IntObjectFormat": "Siebel Hierarchical",
            "ListOfSC EAI Contact": {
                "Contact": 
                {
                    "Email Address": "test555@test.com",  
                    "First Name": "SRI",
                    "Last Name": "TEST",
                    "SC External Customer Id":"1234aew",
                    "Integration Id":"1234aew",
                    "Type":"CRM_Unqualified",
                    "SC Sleep ":"35"
 }}}}}

how to convert above xml to above json format using apim policies. please let me know what can we use to get the exact format of the code. Currently i want to use azure azure apim policies for this to do.

  • You can refer to [Convert XML-to-JSON](https://learn.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#ConvertXMLtoJSON), [Convert response body from XML to Json in API Management Policy Expression](https://stackoverflow.com/questions/57993190/convert-response-body-from-xml-to-json-in-api-management-policy-expression-when), [Azure API Management: json-to-xml policy with consider-accept-header](https://stackoverflow.com/questions/33874106/azure-api-management-json-to-xml-policy-with-consider-accept-header) – Ecstasy Nov 18 '21 at 07:54
  • Could you please help me with your Inbound and Outbound policies for your code – SaiSakethGuduru Nov 19 '21 at 05:36

1 Answers1

1

As suggested by @DeepDave-MT Based on the MS DOC

To convert xml to json we can use the below example of code in our azure apim policy for this

Policy statement

<xml-to-json  kind="javascript-friendly | direct"  apply="always | content-type-xml"  consider-accept-header="true | false"/>

Then try to add the below example to convert

<policies>  <inbound>  <base />  </inbound>  <outbound>  <base />  <xml-to-json kind="direct" apply="always" consider-accept-header="false" />  </outbound>  </policies>
AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15