XML ⇄ JSON Converter
Paste XML to get JSON, or paste JSON to get XML. Attributes carry a prefix such as @, text inside an element goes under a text key, and repeated sibling elements become an array. Values stay as text unless you turn on typed values.
XML ⇄ JSON Converter runs entirely in your browser: the text you paste is never sent to a server. It is free and needs no sign-up.
How to use it
- Convert XML to JSON or back Under Direction, pick XML to JSON or JSON to XML, then paste the text into the Input box. The result updates as you type, and an XML error shows its line and column.
- Set the keys and typed values Attribute prefix (@ by default) marks attributes, and Text key (#text) holds element text. Typed values are off, so every value stays a string until you turn numbers and true or false into typed values.
- Copy the result Press Copy under Result. In JSON to XML mode, set the root element name, which wraps the data when the JSON has several top-level keys, and tick the declaration option if you need it.
Questions
What do the @ prefix and #text key mean?
In XML to JSON, an attribute named id becomes a key such as @id, so it stays apart from child elements. Text inside an element that also has attributes or children goes under #text. You can rename both in the options.
Why is a single item sometimes not an array?
Only sibling elements with the same name are gathered into an array. One element with a unique name stays a single value, so a list with one item can come out as an object. Check the shape before your code reads it.
Which XML details are lost in the conversion?
Comments and processing instructions are dropped, and CDATA counts as plain text. Mixed content, where text sits between child elements, is joined into the text key with single spaces, so its exact position is lost. Keep the original file for that case.