Skip to content
Categories
XML to JSON
Convert XML into JSON format.
Overview
- Converts XML-formatted data into JSON format.
- Attributes are represented with an "@attributeName" key, and the direct text content of an element with no child elements is represented with a "#text" key. This is a common convention used in XML-to-JSON conversion.
- When multiple child elements share the same name, they are converted into a JSON array.
Usage
- Enter the XML you want to convert into the text area.
- Click the "Convert" button.
- The result, converted to JSON format, is displayed below. Use the "Copy" button to copy it to the clipboard.
Example
Input
<person id="1"><name>Taro</name><age>20</age></person>
Output
{
"person": {
"@id": "1",
"name": "Taro",
"age": "20"
}
}Use Cases
- Converting an XML-formatted API response or feed (such as RSS) into JSON to pass to a script or another tool
- Converting an XML configuration file's contents to read them more like JSON
- Feeding in output created with "JSON to XML" to check that the converted result matches expectations
FAQ
Is the XML I enter sent anywhere?
No. The conversion runs entirely in your browser, and nothing is sent to an external server.
How are attributes represented?
They are represented with an "@attributeName" key. For example, `<user id="1">` becomes `{"@id": "1"}`.
Do numbers and booleans become JSON numbers and booleans?
No. Since XML has no type information, all values are converted to JSON strings. Convert them manually afterward if you need numbers or booleans.
Can content that mixes text and elements (mixed content) be converted?
Not fully. For content like "Hello <b>World</b>!" where text and elements are interleaved, only the element portions are converted, and the surrounding text's position is lost.
Notes
- Attributes are represented with an "@attributeName" key, and the direct text of an element with no child elements is represented with a "#text" key (only when the element also has attributes).
- Multiple child elements with the same name are converted into a JSON array, and an empty element (no child elements or text) becomes null.
- All values are converted to strings exactly as written in the XML (no conversion to numbers or booleans is performed).
- Content that mixes text and elements (mixed content) is not fully preserved.
Related Tools
Convert JSON to XML format.
Format XML to make it easier to read.
Validate whether XML syntax is correct.