XML to JSON converter — paste XML, get clean JSON
Convert XML to JSON in one click. Attributes, repeated elements and text are all kept, and you choose pretty or minified output. The XML to JSON converter runs entirely in your browser, so private data never leaves your computer.
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.
How to convert XML to JSON
APIs, payment gateways and old SOAP services still answer in XML, while JavaScript, PHP and most modern code would rather read JSON. Three steps get you from one to the other.
Paste or load the XML
Paste it into the left box, or load an .xml, .rss, .svg or .kml file from your computer. Press Sample to see how a typical document converts.
Pick the options
Keep or drop attributes, choose their prefix, force arrays if your code expects them, and turn on number and boolean detection when you want real JSON types.
Convert and copy
Press Convert (or Ctrl + Enter). Copy the JSON or download it as a .json file. If the XML is broken, you get the line and column of the problem instead.
How XML maps to JSON
XML and JSON do not line up one to one: XML has attributes, mixed text and repeated tags, JSON has objects, arrays and types. This XML to JSON converter follows the widely used conventions below, so the result works with most libraries.
Elements become keys
The root element becomes the single top-level key. Each child element becomes a key inside its parent's object. An element with only text, like <title>Learning PHP</title>, becomes "title": "Learning PHP".
Attributes get a prefix
Attributes become keys starting with @, so they never clash with child elements of the same name:
<price currency="INR">499</price>
→ "price": { "@currency": "INR", "#text": "499" }
Repeated elements become arrays
Two <book> elements under the same parent become "book": [ {...}, {...} ]. A lone element stays an object, unless you tick "Always use arrays", which is handy when the number of items varies from one API response to the next.
Text, CDATA, comments and namespaces
Text and CDATA sections are kept as text, trimmed of surrounding whitespace. Comments and processing instructions are dropped. Namespace prefixes stay in the key names (soap:Body), and xmlns declarations are kept as attributes so nothing is lost. Empty elements such as <empty/> become an empty string.
Doing the same in PHP
On your own server, the quick version is json_encode(simplexml_load_string($xml)). It drops text that sits next to attributes and handles single versus repeated elements differently, which is why the output can differ from this tool. If you need the exact structure shown here, map the elements yourself with DOMDocument.
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 XML to JSON?
Paste your XML into the left box (or load an .xml file) and press Convert. The JSON appears on the right. Copy it or download it as a .json file. The converter keeps attributes, turns repeated elements into arrays and keeps text that sits next to child elements.
How are XML attributes shown in the JSON?
Each attribute becomes a key with an @ in front of its name, so <book id="7"> becomes "book": {"@id": "7"}. You can change the prefix (for example to _ or nothing) or switch attributes off in the options.
What happens to repeated elements?
Two or more elements with the same name under one parent become a JSON array. A single element stays a plain value. If your code always expects an array, tick "Always use arrays" so every element is wrapped in one, even when there is only one.
What is the #text key?
When an element has attributes or child elements and also some text of its own, the text goes into a #text key. An element with only text becomes a plain string, which keeps the JSON short.
Is my XML uploaded anywhere?
No. The conversion runs in your browser with JavaScript's built-in XML parser. Nothing is sent to HostKarle or any other server, so it is safe for SOAP responses, sitemaps, invoices and config files. It even works offline once the page has loaded.
Why does it say my XML is invalid?
XML is strict: every tag must close, tags must nest correctly, there must be exactly one root element, attribute values need quotes and a bare & must be written as &. The error box shows the line and column where the browser's parser gave up.
Can it convert numbers and true/false into real JSON types?
Yes. XML has no types, so everything is text by default. Tick "Detect numbers & booleans" and values like 42, 9.5, true and false become JSON numbers and booleans. Leave it off for things like PIN codes or phone numbers that must keep leading zeros.
How do I convert JSON back to XML?
Use our JSON to XML converter. It reads the same @attribute and #text conventions, so a round trip gives you back equivalent XML.
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