Blog

Convert XML product data to JSON and check arrays and types

Convert sample product data from XML to JSON in your browser and inspect attributes, element text and repeated elements. Screenshots also show how numbers and single-item arrays change after a JSON–XML round trip.

English converter interface showing product XML beside JSON with attributes and tags expanded.

Before passing product data received as XML to a process that reads JSON, check which values become strings and which become arrays. If a product with one tag has a different structure from one with two tags, the receiving code needs to handle both. Try the XML ⇄ JSON converter with some sample product data.

Inspect XML attributes and tags in JSON

  1. Paste the following XML into Input (XML or JSON).
  2. Leave the attribute prefix as @ and the text key as #text, then click XML → JSON.
  3. Inspect product in Output. To save the result, click Copy, paste it into a text editor and save it as product.json.
<product sku="A-104">
  <name lang="en">Desk lamp</name>
  <stock>12</stock>
  <tag>home</tag>
  <tag>lighting</tag>
</product>

The product-code attribute sku becomes "@sku": "A-104". Because the product-name element also has an attribute, the language appears as "@lang": "en" and the name as "#text": "Desk lamp", both under name. The two tag elements become ["home", "lighting"]. The stock value is the quoted string "12".

XML on the left contains a product-code attribute and two tags; JSON on the right shows @sku, #text and a tag array.
English interface. The tag value on the right is an array combining two elements with the same name.

Convert JSON to XML and back to JSON

Start with JSON that already contains a number and an array to see where the structure changes during conversion. Paste the following JSON into the input field.

{
  "product": {
    "@sku": "A-104",
    "stock": 12,
    "tag": ["home"]
  }
}
  1. Click JSON → XML. The output on the right includes <stock>12</stock> and <tag>home</tag>.
  2. Click Copy and replace the contents of the input field on the left with the copied XML.
  3. Click XML → JSON. Check that stock has become "12" and tag has become "home" on the right.
XML on the left contains stock 12 and tag home; the JSON on the right represents both as strings.
JSON converted back from XML. The number 12 and the single-item tag array have both become strings.

The tool reads XML element text as strings. It also creates an array when two or more child elements share a name. If the receiving system expects stock to be a number and tag always to be an array, check each field’s type before saving the output and adjust it to the receiver’s requirements if necessary.

To check for syntax errors, place the data to examine on the left and click Validate XML or Validate JSON. These operations check the input’s syntax. Check field types and item counts by comparing the JSON output on the right with the receiving system’s specification.