XML TO JSON ISSUE

Not applicable

Hello everybody,

I Have an XML like this:

<Items>
	<Item currency="USD">50</Item>
	<Item currency="EUR">35</Item>
</Items>

What I get when I use XML TO JSON POLICY is :

{
  "Items": {
    "Item": [
      {
        "currency": "USD",
        "": "50"
      },
      {
        "currency": "EUR",
        "": "35"
      }
    ]
  }
}

What I want:

{
  "Items": {
    "Item": [
      {
        "currency": "USD",
        "value": "50"
      },
      {
        "currency": "EUR",
        "value": "35"
      }
    ]
  }
}

How can I get it?

Thank you

Solved Solved
1 1 162
1 ACCEPTED SOLUTION

aswinsegu
Participant IV

Hi @Nader Sghir,

Try using <Options>/<TextAlwaysAsProperty> <Options>/<TextNodeName> elements

Use these elements together.

If set to true, the content of the XML element is converted to a string property.

<TextAlwaysAsProperty>true</TextAlwaysAsProperty>
<TextNodeName>TEXT</TextNodeName>

For the following XML:

<a>
	<b>value1</b>
	<c>value2<d>value3</d>value4</c>
</a>

If TextAlwaysAsProperty is set to true and TextNodeName specified as TEXT, the following JSON structure is generated:

{ "a": { "b": { "TEXT": "value1" }, "c": { "TEXT": [ "value2", "value4" ], "d": { "TEXT": "value3" } } } }

If TextAlwaysAsProperty is set to false and TextNodeName specified as TEXT, the following JSON structure is generated:

{
  "a": {
    "b": "value1",
    "c": {
      "TEXT": [
        "value2",
        "value4"
      ],
      {
        "d": "value3",
      }
    }
}

View solution in original post

1 REPLY 1

aswinsegu
Participant IV

Hi @Nader Sghir,

Try using <Options>/<TextAlwaysAsProperty> <Options>/<TextNodeName> elements

Use these elements together.

If set to true, the content of the XML element is converted to a string property.

<TextAlwaysAsProperty>true</TextAlwaysAsProperty>
<TextNodeName>TEXT</TextNodeName>

For the following XML:

<a>
	<b>value1</b>
	<c>value2<d>value3</d>value4</c>
</a>

If TextAlwaysAsProperty is set to true and TextNodeName specified as TEXT, the following JSON structure is generated:

{ "a": { "b": { "TEXT": "value1" }, "c": { "TEXT": [ "value2", "value4" ], "d": { "TEXT": "value3" } } } }

If TextAlwaysAsProperty is set to false and TextNodeName specified as TEXT, the following JSON structure is generated:

{
  "a": {
    "b": "value1",
    "c": {
      "TEXT": [
        "value2",
        "value4"
      ],
      {
        "d": "value3",
      }
    }
}