Pricing
Domains & email
Why HostKarle
About
Contact
See plans Log in

JSON to XML converter — well-formed XML in one click

Turn any JSON object or array into clean, indented XML. Arrays become repeated elements, @keys become attributes, and invalid tag names are fixed for you. The JSON to XML converter runs in your browser, so nothing is uploaded.

Runs in your browser
Your data is never uploaded
Free, no sign-up
Load file

Everything happens in your browser with JavaScript. Nothing you paste is sent to HostKarle or anyone else, so it is safe for API responses, config files and other private data. Shortcut: Ctrl + Enter runs the tool.

Convert JSON to XML online

How to convert JSON to XML

Tally imports, government portals, SOAP services, RSS feeds and many payment and logistics APIs in India still want XML. Here is how to turn the JSON your app already has into XML they accept.

1

Paste or load the JSON

Paste it into the left box or load a .json file. Press Sample to see an invoice with attributes, an array and Unicode text convert.

2

Set the root and prefix

Name the root element your receiver expects, choose the attribute prefix and decide whether you want the <?xml?> declaration and indentation.

3

Convert and download

Press Convert (or Ctrl + Enter), then copy the XML or download it as an .xml file. Invalid JSON is reported with its line and column.

JSON to XML converter rules

How JSON maps to XML

The JSON to XML converter uses the same conventions as our XML to JSON converter, so you can go back and forth without losing attributes or arrays.

Objects and keys

Every key becomes an element and every nested object becomes nested elements, in the same order as the JSON.

Arrays

An array repeats its parent key once per item:

{"tags": ["php", "mysql"]}
→ <root><tags>php</tags><tags>mysql</tags></root>

If you want a wrapper element around the list, nest it in your JSON: {"tags": {"tag": ["php", "mysql"]}}.

An array inside an array keeps its shape: each inner list becomes one element with an <item> per entry, so {"grid": [[1, 2], [3]]} gives <grid><item>1</item><item>2</item></grid><grid><item>3</item></grid>.

Attributes and text

Keys starting with @ that hold a string, number, boolean or null become attributes. A #text key becomes the element's text, so {"price": {"@currency": "INR", "#text": 499}} gives <price currency="INR">499</price>.

Escaping and names

&, < and > in values are escaped, and quotes too inside attributes. Keys that are not legal XML names are made legal with underscores. Unicode text such as Hindi or Malayalam is kept as is, and the declaration says UTF-8.

In PHP

PHP has no one-line JSON to XML function. The usual approach is json_decode($json, true) followed by a short recursive function that calls SimpleXMLElement::addChild() for each key and repeats the key for list arrays, which is exactly what this page does in JavaScript.

JSON to XML FAQs

Frequently asked questions

Something not working the way you expect? Message us on WhatsApp at +91 94343 44325. We are a hosting company, so we answer developer questions too.

How do I convert JSON to XML?

Paste your JSON into the left box (or load a .json file) and press Convert. The XML appears on the right, indented and ready to copy or download as an .xml file.

How are JSON arrays converted to XML?

XML has no arrays, so each item becomes a repeated element named after the key. {"tag": ["php", "mysql"]} becomes <tag>php</tag><tag>mysql</tag>. A top-level array is wrapped in your root element with one <item> per entry.

Can I create XML attributes from JSON?

Yes. Keys that start with @ (or the prefix you set) and hold a plain value become attributes: {"book": {"@id": "7", "title": "PHP"}} gives <book id="7"><title>PHP</title></book>. A #text key becomes the element's own text.

What root element does the XML get?

XML needs exactly one root. If your JSON is an object with a single key, that key becomes the root. Otherwise everything is wrapped in a root element called root, and you can rename it in the options or force the wrapper every time.

What happens to keys that are not valid XML names?

XML element names cannot contain spaces or most punctuation and cannot start with a digit. Such characters are replaced with an underscore and names that start with a digit get an underscore in front, so "2024 sales" becomes <_2024_sales>. Text and attribute values are escaped, so & and < are safe.

Is my JSON sent to a server?

No. The converter is plain JavaScript running in your browser. Your JSON never leaves your computer, which makes it safe for API keys, customer records and internal config.

How do null, true and numbers come out?

Numbers and booleans are written as text (<qty>3</qty>, <paid>true</paid>). null and empty arrays become an empty element such as <discount/>.

My JSON has an error. How do I find it?

The converter shows the line and column where the JSON breaks and a short reason, for example a missing comma or a trailing comma. For a full check and reformat, use the JSON formatter and validator.

Free developer tools

More JSON and XML tools

All of them run in your browser, need no sign-up and work on large files. Bookmark the one you use most.

PHP hosting for developers, from ₹99 a month

Pick the PHP version per domain up to PHP 8.3, with MySQL, phpMyAdmin, cron jobs and free SSL in DirectAdmin, on SSD servers. Host Laravel, CodeIgniter or plain PHP APIs. Renews at the same price.

Also on HostKarle: hosting checker · WHOIS lookup · bulk domain search · shared hosting plans

Chat with us