JSON XML Converter

Paste JSON or XML, choose the direction and get the other format. Attributes, text, repeated elements and empty elements are all handled, and mistakes are reported with a line number.

Direction

In JSON, a key that starts with @ becomes an attribute and #text becomes the text of an element. Going the other way, attributes get an @ in front and repeated elements become a list.

Worked examples

JSON to XML

{"person": {"@id": "7", "name": "Ann & Bo", "tags": ["a", "b"]}}

<?xml version="1.0" encoding="UTF-8"?> <person id="7"> <name>Ann &amp; Bo</name> <tags>a</tags> <tags>b</tags> </person>

The key starting with @ became an attribute, the list repeated the tags element and the ampersand was escaped.

XML to JSON

<shop open="yes"><item sku="a1">Tea</item><item sku="b2">Coffee</item></shop>

{ "shop": { "@open": "yes", "item": [ { "@sku": "a1", "#text": "Tea" }, { "@sku": "b2", "#text": "Coffee" } ] } }

Two item elements became a list, and each keeps its attribute and its text.

About JSON XML Converter

JSON and XML are the two formats you meet most often when systems exchange data. Newer web services speak JSON, while many feeds, document formats, payment and government interfaces and older enterprise tools still expect XML. When you have one and need the other, a converter saves you from rewriting the structure by hand and getting a closing tag wrong.

This converter works in both directions. Elements that repeat become a JSON list, attributes are kept with an @ in front of their name, and text that sits beside child elements is kept under #text. Going to XML, a single top level key becomes the root element, awkward key names are tidied so the result is well formed, and special characters in text are escaped. If the input has a mistake, you are told the line and column.

How to use JSON XML Converter

  1. Choose JSON to XML or XML to JSON.
  2. Paste your input into the box. The result appears as you type.
  3. Set the options: the root element name and declaration for XML output, or number conversion for JSON output.
  4. Copy the result, or read the line number in the message if the input has a mistake.

Common uses

  • Sending data to a service that only accepts XML
  • Reading an XML feed as JSON in a script or spreadsheet
  • Checking how a structure looks in the other format before you design an interface
  • Migrating configuration from an older XML file to JSON

Frequently asked questions

How are XML attributes shown in JSON?

Each attribute becomes a key with an @ in front of its name, so <book id="7"> becomes {"book": {"@id": "7"}}. Going back, keys that start with @ become attributes again.

What happens to repeated elements?

Elements with the same name inside one parent become a JSON list. A single element stays a plain value, so a list with only one item reads back as one item, which is a known limit of the format.

Why is null shown as an empty element?

XML has no null value. A null in JSON is written as an empty element such as <empty/>, and an empty element is read back as null.

Are numbers kept as numbers?

XML holds only text. By default values stay as text. Tick the option to turn plain numbers and true or false into JSON values. Values with leading zeros, such as 007, stay as text.

Can it read XML with namespaces, comments or CDATA?

Comments are skipped, CDATA text is kept as text, and prefixed names such as ns:item are kept as written. A document type declaration is read and ignored.