JSON and XML converter
Runs in your browser; nothing is uploaded
Convert JSON to XML or XML to JSON, with attributes, repeated elements and namespaces handled explicitly.
Input · JSON
Output · XML
Converted XML appears here as you type.
JSON and XML in APIs
JSON and XML both describe structured data as text. JSON has objects, arrays and typed values such as numbers and booleans. XML has nested elements, attributes and text, and everything is text unless a schema says otherwise. SOAP web services, RSS and Atom feeds, and many banking, payment and government systems still use XML, so apps built on JSON often have to translate.
The two formats don't map one to one, so this converter follows a common, reversible convention. An element becomes a key and its text the value. Attributes become keys starting with @, such as @id. When an element has attributes or child elements as well as text, the text goes in #text. An element that repeats becomes an array. Namespace prefixes are kept as written, so <soap:Body> becomes "soap:Body" and the declaration becomes "@xmlns:soap".
XML has no types, so by default everything stays a string: <zip>007</zip> gives "007" and <id>7</id> gives "7". Turn on Numbers to read values written exactly as JSON numbers, and true and false, as typed values (007 still stays text). Going the other way, the root element comes from the JSON's single top-level key, or from the Root name when there are several.
How to use this tool
- 1Choose JSON → XML or XML → JSON in the toolbar. Paste your data into the Input pane, drop a file on it, or press Ctrl+O to open one (up to 5 MB).
- 2Read the result in the Output pane; it updates as you type. Notes above the output say what the conversion had to change, such as renamed keys or comments left out.
- 3For XML → JSON, choose Always arrays to make every child element an array (simpler to read from code) and Numbers to convert numbers and booleans. For JSON → XML, set the Root name and whether to start with an XML declaration.
- 4If the input is invalid, the output pane gives the line and column; press F8 to put the cursor on the problem.
- 5Swap (Shift+Alt+S) puts the output into the input and flips the direction, to check the round trip. Copy the result, or download it with Ctrl+S.
Troubleshooting
- Expected </item> to close the element opened on line 3
- Tags must close in the reverse order they were opened, with the same name and case. Check the element named in the message for a missing or misspelt closing tag.
- A bare
&must be written as& - In XML text and attributes,
&starts an entity. Write&for an ampersand,<for<, or wrap the text in<![CDATA[ ... ]]>. - Unknown entity
- Only the five XML entities (
<>&"') and character references such as are defined. comes from HTML; use instead. - A second root element: XML has exactly one
- An XML document must have a single top-level element. Wrap the elements in one parent element.
- Keys renamed in the XML output
- XML names can't contain spaces or most punctuation, or start with a digit, so
first namebecomes<first_name>and2fabecomes<_2fa>. The note lists each rename; change the keys in the JSON if the XML must use other names.
Frequently asked questions
How are JSON arrays converted to XML?
Each item becomes an element named after the array's key, repeated once per item: "tag": ["a", "b"] becomes <tag>a</tag><tag>b</tag>. A top-level array is wrapped in the root element with one <item> per entry. An empty array produces no elements, so it can't come back on the way to JSON; the notes say when that happens.
What happens to comments, CDATA and processing instructions?
CDATA sections become ordinary text. Comments and processing instructions have no place in JSON and are left out, with a note. A DOCTYPE is skipped, and entities it declares aren't expanded.
What about mixed content, such as `<p>Hello <b>world</b></p>`?
The child elements become keys as usual and the surrounding text is collected in #text. JSON can't record where the text sat between the elements, so that order is lost; the converter adds a note when this happens.
Is the conversion done on a server?
No. XML is parsed and written in your browser, and nothing you paste or open is uploaded. To survive a reload, what you paste is kept in this tab's session storage until you clear it or close the tab. Copy link puts the input in the link after #, which browsers never send to a server, but anyone you give the link to can read it.