我想使用apim策略将xml转换为json



示例xml请求:

<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"
}}}}}

如何使用apim策略将上面的xml转换为上面的json格式。请告诉我我们可以用什么来获得代码的确切格式。目前我想使用azure azure apim策略来做这件事。

根据@DeepDave MT基于MS DOC 的建议

将xml转换为json,我们可以在此的azure apim策略

政策声明

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

然后尝试添加以下示例来转换

<policies>  <inbound>  <base />  </inbound>  <outbound>  <base />  <xml-to-json kind="direct" apply="always" consider-accept-header="false" />  </outbound>  </policies>

最新更新