About JSON to XML
Many older systems, from payment gateways to government filing portals, still take XML. If your data lives in JSON, the conversion has traps: keys with spaces are not valid names, a top-level list has no root, and an & in a value breaks the whole document.
This tool handles those issues and tells you when it had to change a name. It also lets you write attributes from JSON using @ keys, so you can produce the structure a receiving system expects, not just a pile of child elements.
The result is XML that any parser will accept, ready to copy or download with an optional declaration on the first line.
How it works
A JSON object with one key uses that key as the root element. Anything else, such as several keys, a list or a lone value, is wrapped in a root you can name in Options. A list under a key repeats that element, which is how XML normally shows a collection.
Keys beginning with @ become attributes, and @attributes holding an object works too. #text sets the element's text, and #cdata writes a CDATA section, safely splitting any ]]> inside it. Output from our XML to JSON tool can come straight back this way.
Values are escaped, and invalid characters in names are replaced with underscores, with a notice listing what changed. Names may use any Unicode letter, so 名前 stays as it is. Control characters that XML 1.0 cannot represent are removed, and you are told.
How to use JSON to XML
- Paste JSON into the input box, or use Open file.
- Add
@to any key that should be an attribute, right in the input. - Under Options, set the Root element and List item element names your receiver expects.
- When it looks right, use Copy or Download .xml.
Attributes from @ keys, escaping and a repeated element
{"order":{"@id":"A-1042","customer":"Lovelace & Daughters","line":[{"@sku":"PEN-1","qty":2},{"@sku":"INK-9","qty":1}],"note":null}}<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1042">
<customer>Lovelace & Daughters</customer>
<line sku="PEN-1">
<qty>2</qty>
</line>
<line sku="INK-9">
<qty>1</qty>
</line>
<note />
</order>@id and @sku became attributes, & was escaped, the line list repeats the element, and null produced an empty <note />.
When it helps
- Building a request for a SOAP or XML-RPC service from JSON test data.
- Producing a sitemap or simple feed from a list of records.
- Creating an XML fixture for a parser's test suite.
- Sending data to an accounting or logistics system whose import format is XML.
Tips for a better result
- Validate the result against your receiver's XSD if it has one. Element order often matters there, and this tool keeps the order of your JSON keys.
- A list inside a list gets its own wrapper elements named by the List item element option, so its grouping survives.
- A leading digit in a key gets an
item_prefix, since XML names cannot start with a number. Rename keys first if the receiver is picky.
Good to know
- XML has no types, so numbers and booleans are written as text, and null and an empty string both give an empty element.
- Namespaces are not managed for you. Write
xmlnsattributes yourself with@xmlnskeys, and a prefix is not checked for a matching declaration. - It writes well-formed XML, but cannot check validity against a schema it has not seen.
- Output is always indented with two spaces. Whitespace-sensitive receivers may need it minified afterwards.
Questions people ask
How do I make an attribute instead of a child element?
Start the key with @: {"book": {"@id": "1", "title": "Emma"}} gives <book id="1"> with a title child. An object under @attributes does the same. The value needs to be plain, not an object or list.
Why was my top-level list wrapped in another element?
An XML document must have exactly one root element, so a list cannot be written directly. It goes inside the Root element, with each item named by the List item element option.
Why was one of my keys renamed?
XML names cannot contain spaces and most punctuation, or begin with a digit. first name becomes first_name, 1st becomes item_1st, and a notice lists every name that changed.
Can I write CDATA?
Yes, with a #cdata key on the element. Everything else is escaped as ordinary text, which any XML parser reads back the same way.
What to use next
- XML to JSON: to confirm the XML reads back as you intended
- JSON Validator: when the JSON input has a syntax problem
- CSV to XML: if your source data is a spreadsheet
Last reviewed . Read our editorial policy.