JsonToXml Policy Help: Why does ObjectRootElementName only get outputted when a JSON array is provided?

When I’m converting JSON to XML using the following policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML async="false" continueOnError="false" enabled="true" name="JX-TransformInputJsonToXml">
    <DisplayName>Transform Input JSON to XML</DisplayName>
    <Properties/>
    <Options>
        <NullValue>NULL</NullValue>
        <NamespaceBlockName>#namespaces</NamespaceBlockName>
        <DefaultNamespaceNodeName>$default</DefaultNamespaceNodeName>
        <NamespaceSeparator>:</NamespaceSeparator>
        <TextNodeName>#text</TextNodeName>
        <AttributeBlockName>#attrs</AttributeBlockName>
        <AttributePrefix>@</AttributePrefix>
        <InvalidCharsReplacement>_</InvalidCharsReplacement>
        <ObjectRootElementName>Root</ObjectRootElementName>
        <ArrayRootElementName>Array</ArrayRootElementName>
        <ArrayItemElementName>Item</ArrayItemElementName>
    </Options>
    <OutputVariable>xmlGeneratedFromJson</OutputVariable>
    <Source>request</Source>
</JSONToXML

I notice that is only outputted when I provide a JSON array. For example:

{"foo": "bar"}

will result in:

<foo>bar</foo>

and not

<Root><foo>bar</foo></Root>

@Zameer Andani , Looks like it’s by design, As per docs, “specifies the root element name when you convert from JSON, which does not have a named root element, to XML.” I believe in single property case “foo” will become the root for the text “bar”.

If you have JSON with more than one property it does add root element to wrap the response output. For example,

{"foo": "bar", "hello": "world"}

Will result in ,

<Root>
  <foo>bar</foo>
  <hello>world</hello>
</Root>

Please find attached sample proxy that demonstrates above.

jsonoutput-rev1-2017-05-28.zip

Hope it helps.