JSON and XML converter
Everything runs in your browser; nothing is sent or stored.
- Paste your data into the "JSON or XML" field, and click "JSON to XML" or "XML to JSON". XML with a DOCTYPE or ENTITY declaration is refused, to prevent external files from loading and entities from expanding.
- In JSON, a key that starts with @ becomes an attribute, and the #text key becomes the element text. An array becomes repeated elements with the same name. When converting XML to JSON, every value is text, and an element that repeats becomes an array.
- In the "Root element name" field, set the name of the element that wraps the data when converting to XML.
- Below the result, the tool shows its number of characters and the root element name, and when converting to XML, also messages about fixed names and replaced characters.
- Copy the result by clicking "Copy".
Differences between JSON and XML
JSON has objects, arrays, and value types such as numbers, text, true/false, and null. XML has elements, attributes, and text, with no value types and no separate structure for arrays. That is why, when converting to XML, every key becomes an element, and an array becomes repeated elements with the same name, one element for each item. A top-level JSON array is wrapped in the root element, and each of its items becomes an element named item. A null value and an empty object become an empty element, and characters such as & and < in text are escaped according to XML rules.
Converting XML to JSON
When converting to JSON, each attribute becomes a key that starts with @, and an element that appears several times under the same parent element becomes an array. An element that appears only once does not become an array, so the same structure can come out as an array in one document and as a single value in another. Code that reads the JSON needs to handle both cases, for example by wrapping a single value in an array. Comments in the document are not included in the result, and the content of CDATA sections becomes regular text.
Common uses of XML
XML is still used in SOAP APIs, RSS feeds, website sitemap files, and the configuration files of many systems, as well as for exchanging data between older systems. When a new application works with JSON and needs to send data to a system that accepts XML, or read data from it, the converter quickly shows the same data in both formats. To format an XML document and check that it is valid before converting it, you can use the "XML formatter" tool.
JSON keys and how they convert to XML
"@id": "1"a key that starts with @ becomes the id attribute of the element, with the value 1."#text": "Hello"the text of an element that also has attributes."tags": ["SSD", "SSL"]an array becomes two elements named tags, one for each value."note": nulla null value becomes an empty element named note."first name": "Dana"a key with a space becomes an element named first_name, because an element name cannot contain a space."1st": "x"a name that starts with a digit gets an underscore at the start, and the element is named _1st."prénom": "Dana"names with accented letters or letters from other alphabets are valid in XML and stay as they are.
JSON and XML converter FAQ
How is the root element of the XML document determined?
When the top level of the JSON has a single key that is not an attribute or #text, and its value is not an array, that key becomes the root element. In any other case, the data is wrapped in an element whose name is set in the "Root element name" field, and the default name in the field is root.
Does converting back and forth return the same JSON?
Converting back and forth does not always return the same JSON. Numbers and true/false values come back as text, null and an empty object come back as an empty string, and an array with one item comes back as a single value. Data that was wrapped in the root element comes back inside an extra key named after the root element.
Why is an XML document with a DOCTYPE not converted?
DOCTYPE and ENTITY declarations can define entities that point to external files (an XXE attack) or entities that expand into a huge amount of text. That is why a document with DOCTYPE or ENTITY declarations is not converted. When the document does not use the entities defined in it, you can remove the declarations and convert again.
Why do I get an error for an XML document that looks valid?
A valid XML document requires every element to be closed, the & and < characters in text to be written as & and <, and the document to have only one root element. When the location of the error can be found, the message shows the line and the column, and after you click "XML to JSON", the cursor moves to the location of the error in the field.
What happens to characters and names that are not valid in XML?
When converting to XML, control characters that are not allowed in an XML document are replaced with the � character. When two attribute keys get the same name after their names are fixed, such as @a b and @a_b, the second attribute is dropped.
What is the maximum size of a JSON or XML file to convert?
The input can be up to 1 MB, and a nested structure is converted up to a depth of 100 levels.