Paste JSON or upload a file
Add an object, array, API response, or data export. Use the sample button to see attributes and repeated XML elements.
Convert JSON objects, arrays, and API responses to clean XML in one click, or switch directions and parse XML back to JSON. Set root and item tags, preserve attributes, include the XML declaration, and download a ready to use file. All conversion happens locally in your browser.
JSON and XML both describe trees, so the conversion is more natural than flattening to a spreadsheet. Three rules cover almost every case.
The array rule is the one with consequences. Since the brackets vanish, an array of one element and a bare object produce identical XML. That ambiguity is why converting back from XML to JSON needs either a schema or a convention.
A small product catalogue, shown as JSON and as the XML it produces.
JSON input
XML output
JSON keys are arbitrary strings. XML element names are not, and this is where most conversions actually break. An XML name must start with a letter or an underscore, may not start with a digit, may not contain spaces, and may not begin with the sequence xml in any casing, which is reserved.
| JSON key | Valid element? | Typical transformation |
|---|---|---|
| firstName | Yes | firstName, used unchanged |
| first name | No, space | first_name or firstName |
| 1st | No, leading digit | _1st or n1st |
| order-total | Yes | Hyphens are legal after the first character |
| user.id | Yes but risky | Full stops are legal but read as a path by some tooling |
| xmlData | No, reserved prefix | x_xmlData |
| (empty string) | No | item or a positional fallback |
| price (£) | No, space and symbol | price_gbp |
Pick one transformation policy and apply it consistently, because the mapping needs to be predictable if anything downstream will parse the result.
This is the design decision with no correct answer, and JSON gives you no hint either way because it has only keys and values. The same data can be modelled both ways.
Two valid encodings of the same record
The usual guidance is that attributes carry metadata about the element (identifiers, units, language codes, flags) while child elements carry the content itself. Attributes cannot repeat, cannot nest, and cannot hold structure, so anything that might grow later belongs in an element. Converters default to all elements because it is the only choice that never loses the ability to expand a value into a subtree.
A well formed XML document conventionally opens with a declaration naming the version and the character encoding. It is optional in XML 1.0 but including it removes any doubt about how the bytes should be decoded.
Five characters have special meaning inside XML and must be replaced with their predefined entities when they appear in text content.
| Character | Entity | Required in |
|---|---|---|
| < | < | Text content and attribute values |
| > | > | Text content, recommended everywhere |
| & | & | Text content and attribute values |
| " | " | Attribute values quoted with double quotes |
| ' | ' | Attribute values quoted with single quotes |
Missing the ampersand is the classic failure. A company name such as Marks & Spencer produces a fatal parse error, not a warning, because the parser reads the ampersand as the start of an entity reference.
XML requires a single outermost element. JSON has no such rule, so a top level array has nowhere to go and needs a synthetic wrapper. An array of three orders becomes an orders element containing three order elements. Choose the wrapper name deliberately, since it becomes part of the contract for anything reading the document, and a generic name like root tells the consumer nothing.
XML is rarely the last stop. Explore the full converter collection for XML to JSON to reverse the transformation, JSON to YAML when the target is a config file rather than a document, and JSON Schema when you need validation rules similar to what an XSD would give you.
Add an object, array, API response, or data export. Use the sample button to see attributes and repeated XML elements.
Set root and array item names, choose indentation, and include or remove the XML declaration.
Output updates live as you type. Copy the XML or download a ready to use .xml file.
Turn JSON API data into XML for legacy integrations, feeds, import jobs, SOAP-style workflows, and schema-driven systems without exposing the payload.
Private payloads stay in your browser. No uploads, storage, or server processing.
Generate XML live with useful errors for invalid JSON or malformed XML.
Edit root tags, item tags, indentation, and XML declaration output.
Use @ keys for XML attributes and #text for text mixed with child elements.
Parse XML back into structured JSON with attributes and repeated elements preserved.
Copy XML or download a ready to use file for integrations and imports.
Need to convert XML back to JSON? Use the XML to JSON tab or click Swap. Paste any XML document and get structured JSON output instantly. Attributes are preserved with @ prefixes and text content with #text so the conversion is lossless.