Hello,
I’m having some trouble properly converting JSON arrays to equivalent XML arrays using the JSON to XML policy. The JSON object used in the request is as follows:
{
"message": {
"returnMsg": "Data processed successfully",
"returnCode": 0
},
"recipientGroups": [
{
"id": 11,
"name": "Test Group 1",
"description": "Test Group 1 Description",
"recipientGroupSites": []
},
{
"id": 12,
"name": "Test Group 1",
"description": "Test Group 1 Description",
"recipientGroupSites": []
},
{
"id": 13,
"name": "Test Group 1",
"description": "Test Group 1 Description",
"recipientGroupSites": []
}
]
}
The resulting XML is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<cpc>
<message>
<returnMsg>Data processed successfully</returnMsg>
<returnCode>0</returnCode>
</message>
<recipientGroups>
<id>11</id>
<name>Test Group 1</name>
<description>Test Group 1 Description</description>
</recipientGroups>
<recipientGroups>
<id>12</id>
<name>Test Group 1</name>
<description>Test Group 1 Description</description>
</recipientGroups>
<recipientGroups>
<id>13</id>
<name>Test Group 1</name>
<description>Test Group 1 Description</description>
</recipientGroups>
</cpc>
What I would like to achieve is XML of the following form
<?xml version="1.0" encoding="UTF-8"?>
<cpc>
<message>
<returnMsg>Data processed successfully</returnMsg>
<returnCode>0</returnCode>
</message>
<recipientGroups>
<recipientGroup>
<id>11</id>
<name>Test Group 1</name>
<description>Test Group 1 Description</description>
</recipientGroup>
<recipientGroup>
<id>12</id>
<name>Test Group 1</name>
<description>Test Group 1 Description</description>
</recipientGroup>
<recipientGroup>
<id>13</id>
<name>Test Group 1</name>
<description>Test Group 1 Description</description>
</recipientGroup>
</recipientGroups>
</cpc>
The JSON to XML policy options I use are as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML async="false" continueOnError="false" enabled="true" name="JSON-to-XML-1">
<DisplayName>JSON to XML</DisplayName>
<Properties/>
<Options>
<NullValue>NULL</NullValue>
<NamespaceBlockName>#namespaces</NamespaceBlockName>
<DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName>
<NamespaceSeparator>:</NamespaceSeparator>
<TextNodeName>#text</TextNodeName>
<AttributePrefix>$</AttributePrefix>
<InvalidCharsReplacement>_</InvalidCharsReplacement>
<ObjectRootElementName>cpc</ObjectRootElementName>
<ArrayRootElementName>Array</ArrayRootElementName>
<ArrayItemElementName>Item</ArrayItemElementName>
</Options>
<OutputVariable>response</OutputVariable>
<Source>response</Source>
</JSONToXML>
I’ve also tried replacing the ArrayRootElement and ArrayItemElement to recipientGroups and recipientGroup respectively. For some reason this doesn’t change the resulting XML in any way.
Was wondering if anyone could provide any insight into this.
Thanks,
Brad Sheppard