About the XML to JSON Converter
Feeds, sitemaps, invoices and older APIs still deliver XML, while most modern code works with JSON. This XML to JSON converter parses the document with your browser's own XML parser and rewrites it as JSON, keeping attributes under a predictable key, turning repeated elements into arrays automatically and handling CDATA sections, comments and namespaces. Malformed XML is reported with the parser's error message, so you can find the problem quickly. The output is formatted for easy reading. To go back again, use the JSON to XML Converter, and for browsing the result, the JSON Viewer.
XML can express things that JSON has no direct slot for, so the output follows a well-known convention instead of improvising. Attribute values are collected in an object labelled @attributes, the text of an element that also has attributes or children goes into #text, and same-named siblings are bundled into one array. Because the convention is widely used and predictable, code that consumes the JSON is easy to write.
The document is checked strictly before any conversion takes place. A missing end tag or an unescaped ampersand stops the process with a message that names the line, instead of producing JSON for half the file. XML is meant to be strict, and a converter that hides errors does more harm than good. Prefixed names, protected CDATA text, comments and processing instructions all make it through instead of being thrown away. The work happens in your own browser, so invoices, feeds and internal configuration never leave your computer.
How to use the XML to JSON Converter
- Paste the XMLA complete document or a fragment; it is checked strictly in both cases.
- Pick an attribute styleKeep attributes under @attributes, or merge them into the element's object if the program reading the JSON expects a flatter shape.
- Read any error messageInvalid XML is reported with the line number and the reason.
- Take the JSONCopy or download the indented result.
XML to JSON Converter features
- Strict parsing by the XML parser inside your browser
- Attributes kept under a consistent key
- Same-named siblings grouped into lists without any setup
- CDATA sections, comments and namespaces supported
- Errors that give the line and the cause
- Indentation you can adjust
- Conversion that never leaves your device
Common uses
- Using an XML web service from JavaScript code
- Turning an RSS feed or sitemap into data for a script
- Moving an application's settings from XML to JSON
- Reading an unfamiliar XML document in a simpler shape
- Feeding XML data to a tool that only accepts JSON
XML to JSON in practice: courier tracking responses, the single-item trap, RSS feeds and sitemaps, SOAP envelopes and safe parsing
Plenty of useful data still arrives as XML: courier tracking responses, bank and payment interfaces, government services, RSS feeds and XML sitemaps. Converting it to JSON makes it far easier to use in modern code, but the conversion exposes differences between the formats that cause bugs if they are not handled. This guide works through a tracking response, explains the single-item trap, covers feeds, sitemaps and SOAP, and explains a server-side security risk worth knowing about.
A worked example: a tracking response
A courier's tracking service returns:
<shipment id="TRK-5521"><status>In transit</status><event time="2026-10-24T09:15:00+05:00">Picked up, Lahore</event><event time="2026-10-25T07:40:00+05:00">Arrived, Karachi hub</event></shipment>
Converted to JSON, the shipment's id attribute appears under @attributes, status becomes a simple string, and the two event elements become an array of two objects, each with its time attribute and its text under #text. Code can now loop over the events to show a delivery timeline on an order page.
The single-item trap
Repeated elements become an array, but a shipment with only one event has no repetition, so event becomes a single object instead of an array with one item. Code written and tested against the two-event example then fails on the first parcel that has just been picked up. Normalising such fields in your code, by wrapping a single object in an array whenever a list is expected, prevents this very common bug.
Everything starts as text
XML has no separate number, boolean or date types, so values such as quantities, prices and true or false arrive as text. Your code should convert them deliberately: parse amounts as numbers, compare status flags as strings and parse dates including their time zone offsets. Relying on automatic guessing leads to surprises, such as codes with leading zeros losing them.
RSS feeds
Blogs and news sites publish RSS or Atom feeds in XML. Converting a feed to JSON makes it easy to display recent posts on another site or app: each item element becomes an object with title, link, publication date and description. Descriptions often contain HTML, either escaped or inside CDATA sections, so treat that content as untrusted and sanitise it before showing it on a page.
XML sitemaps
Sitemaps list a site's URLs with optional last-modified dates. Converting a sitemap to JSON makes analysis straightforward: count the URLs, find pages that have not been updated for years, or compare the list with pages that receive search traffic. Large sites split sitemaps into an index pointing to several files, each of which can be converted in turn.
SOAP responses
SOAP services wrap their data inside an Envelope and a Body element, usually with namespace prefixes on every name. After conversion, the useful data sits a few levels deep, under keys that include those prefixes. Navigating to the inner result object once, and working from there, keeps the rest of your code free of envelope details.
Mixed content
XML can mix text and elements inside one element, as in a paragraph containing a bold word. JSON has no natural way to represent text interleaved with child elements, so such content is split into separate pieces and its original order is hard to rebuild. Document-style XML, such as rich text, is often better processed as XML than converted.
Parsing XML safely on servers
Server-side XML parsers can be tricked by documents that declare external entities, a vulnerability known as XXE, into reading local files or making network requests. Browsers do not fetch external entities when parsing in a page, but server code must disable document type definitions and external entities unless they are genuinely needed. Most modern libraries offer a safe setting, and it should be the default in your code.
Common mistakes
- Assuming a repeated element is always an array.
- Using numbers and dates from XML without converting them.
- Showing feed descriptions without sanitising their HTML.
- Parsing untrusted XML on a server with external entities enabled.
Related tools
To convert JSON back into XML, use JSON to XML Converter. To indent and check the source, try XML Formatter, and to explore the converted result, JSON Viewer.
Large documents
Very large XML files, such as product catalogues with tens of thousands of items, can be slow to convert in a browser tab and produce JSON that is heavy to work with. Servers handle such files with streaming parsers that process one element at a time without loading everything into memory. For designing code, converting a representative sample is usually enough.
Keeping test fixtures
Save a few real responses, with personal details removed, alongside their converted JSON as test fixtures. Include awkward cases: a single item, no items, an error response and text containing Urdu or special characters. When a partner changes their XML without warning, tests built on these fixtures show exactly what changed.
Privacy
Conversion uses your browser's own XML parser. Documents are not uploaded, logged or stored.
Frequently asked questions
Where do the attributes end up?
By default they sit under an @attributes key inside each element's object, which keeps them visibly separate from child elements. If the code receiving the data prefers it, you can merge them straight into the object instead.
How are repeated elements converted?
Several siblings with the same name become an array. A name that occurs a single time stays a plain object, so if the count can vary between documents, write your code to accept both forms.
What happens if the XML is broken?
Conversion stops and you get a message naming the line and the problem, with no partial output. Guessing at broken XML would only hide the fault, so it is better to see exactly where the document needs fixing.
Are namespace prefixes preserved?
Yes. Names keep their prefixes exactly as written, so an attribute such as xsi:type or an element such as atom:link appears in the JSON with the same name it had in the XML.
How is CDATA treated?
The contents of a CDATA section become ordinary text in the JSON, because that is what the section represents: text that was simply protected from the XML parser, often HTML snippets or code samples inside a feed.
Is the XML I paste uploaded?
No. Both the parsing and the conversion take place inside your browser, so feeds, invoices and configuration files are never sent to a server or stored anywhere.