XML to JSON: Keep Attributes and Text

An XML element can have attributes and a text value at the same time. In the AIToolMaps converter, attributes use a configurable prefix and the text is stored under #text when the result needs an object.

Worked example

XML input

<item sku="0007">Keyboard</item>

Actual JSON output with the default prefix

{
  "item": {
    "#text": "Keyboard",
    "@_sku": "0007"
  }
}

Steps

  1. Select XML to JSON and leave Keep attributes enabled. Choose a prefix your downstream code can distinguish from child element names.
  2. Leave typed values off when identifiers, postcodes, or version strings need to keep leading or trailing zeroes.
  3. Check the generated JSON and update the consumer to read the actual keys, such as @_sku and #text.

What to check

  • Test at least one element with text and an attribute. Turning off attribute preservation drops its SKU.
  • This is the mapping used by the linked converter. Confirm the prefix and type settings if a separate system parses the same file.

Open the XML to JSON converter

References