Convert XML to JSON: attributes not being picked up

Not applicable

Hello,

Following this my understanding is that with a JSON payload that contains:

"description": {
	"@attribute_test" : true
}

I should get:

<description attribute_test="true" />

but I actually get:

<description>
	<null>true</null>
</description>

or with a JSON payload:

"description" : {
    "#attrs" : {
        "attribute_test" : "true"

    }
}

I should get:

<description attribute_test="true" />

but I actually get:

<description/>

The xmltojson policy is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML async="false" continueOnError="false" enabled="true" name="JSON-to-XML">
    <DisplayName>JSON to XML</DisplayName>
    <Properties/>
    <Options>
        <AttributeBlockName>#attrs</AttributeBlockName>
        <AttributePrefix>@</AttributePrefix>
    </Options>
    <OutputVariable>response</OutputVariable>
    <Source>response</Source>
</JSONToXML>

The rest of the XML conversion seems to be succesful. Any idea?

Solved Solved
1 4 918
1 ACCEPTED SOLUTION

Hi @alex.tylor,

In the policy we are specifying the AttributePrefix as "@".

So, the request #attrs that needs to be prefixed with "@"

{ "description" : { "#attrs" : { "@attribute_test" : "true" } } }

View solution in original post

4 REPLIES 4

Hi @alex.tylor,

In the policy we are specifying the AttributePrefix as "@".

So, the request #attrs that needs to be prefixed with "@"

{ "description" : { "#attrs" : { "@attribute_test" : "true" } } }

Thank you that worked a treat

You are welcome. Glad it worked.

Hello @Abhishek Subramanya, I am trying to get json response using axis2 service. It is prefixing @ symbol in front of all attributes. But I need without symbol. Could you please help me on this. Thanks in advance