NHRepon
Home
Services
All ServicesWeb Application DevelopmentMobile Application DevelopmentDigital Marketing and SEO
ProjectsToolsProductsPostsAboutContactLogin
HomeServicesProjectsToolsProductsPostsAboutContact
  • Home
  • Projects
  • Posts
Home/Tools/Converters/XML to JSON
All Tools

XML to JSON Converter

Convert an XML document into JSON, with attributes, mixed text and repeated elements mapped the way you choose — and a check that the XML is well-formed before anything is converted.

Paste an XML document or a fragment. Anything that is not well-formed is reported with the parser's own message instead of being converted approximately.

The parts of XML that do not fit in JSON

The two formats are not equivalent, and the conversion is a set of decisions rather than a translation. Attributes have no counterpart in JSON, so they need a convention: prefixing them with @ keeps them distinguishable from a child element of the same name, which matters because <book id="1"> and<book><id>1</id></book> would otherwise collapse to the same JSON.

Mixed content is the harder problem. An element may hold text, child elements and both interleaved, and JSON has no way to preserve the order of that interleaving — a paragraph with a link in the middle becomes a text key and a link key, and the position of the link is lost. That is why documents that are really narrative markup, such as an article body, convert badly; documents that are records and lists convert well, which covers most of what XML is actually used for on the web.

Arrays are the third decision, and the practical one. Whether a repeated element becomes an array is obvious, but what to do with a single occurrence is not: treating it as an object means the shape of the JSON changes as soon as a second item appears, which breaks consumers. The always-array option trades tidiness for a stable shape, and choosing it up front is cheaper than discovering the problem in production. One last thing the tool will not do is invent data: namespaces are kept as part of the element name, and a processing instruction or a comment in the source is dropped, because neither has a place in the result.

What does an XML to JSON converter do?

It reads an XML document and produces the equivalent JSON, so that data defined in one format can be consumed by code written for the other. That is more or less a daily need: SOAP responses, RSS and Atom feeds, configuration files, sitemaps and the output of older enterprise systems are all XML, while the code that wants to read them almost always expects objects.

The conversion is not a translation, because the two formats do not describe the same things. XML has attributes, mixed content in which text and elements interleave, and comments and processing instructions; JSON has none of those. Each one has to be given a convention, and the conventions differ between implementations, which is why two XML to JSON tools produce different output from the same input.

This tool makes those decisions visible. Attributes can be prefixed so they cannot collide with a child element of the same name, mixed text can be kept under a text key, and a repeated element becomes an array. A single occurrence is the awkward case — an object by default, or a one-item array for a stable shape — and that is offered as a choice rather than decided for you.

How to convert XML to JSON

  1. Paste an XML document into the box, or press Load an example for a small catalogue with attributes and repeated elements.
  2. Watch for a parse error. Anything not well-formed is reported with the parser's own message, and nothing is converted.
  3. Decide how attributes should appear. The default prefixes them with @ so an id attribute and an id child element stay distinct.
  4. Decide the array behaviour. Leave it off for the tidiest JSON, or turn it on so every child is an array and the shape does not change when a second item arrives.
  5. Choose an indentation, or Minified for the smallest output.
  6. Copy the JSON, or download it as a file named after the root element.

XML to JSON Converter limits and rules

Limits, caps and standards referenced by this tool
ItemLimit
InputA well-formed XML document or fragment
AttributesUnder a prefix of your choice, @ by default
TextElement text becomes a string when there are no children or attributes
Mixed contentText kept under a text key alongside the child elements
Repeated elementsAlways an array, whatever the count
Single elementsAn object by default, or a one-item array if you ask for it
NamespacesKept as part of the element name, prefix and all
DroppedComments, processing instructions and the XML declaration itself

When to use it

  • Turning a SOAP or REST response into objects your code can read directly.
  • Converting an RSS or Atom feed into JSON for a front-end that does not parse XML.
  • Reading a configuration file or a sitemap into a script you are writing.
  • Inspecting an unfamiliar XML document to see its structure before writing a parser for it.
  • Producing fixture data in JSON from an XML sample, for tests.

Is it private?

The XML is parsed by the browser's own parser inside this page. Nothing is uploaded, stored or logged, which matters if the document contains a customer record, a licence file or anything else you would rather not paste into a web service.

Frequently asked questions

Because otherwise the conversion is lossy in a way that bites later. XML lets an element have both an attribute called id and a child element called id, and the two are different pieces of data; without a distinguishing convention they collapse into one key in the object and whichever was written last wins. The @ prefix is what the widely used xml2js convention in the JavaScript world does, and the tool lets you change the prefix if your consumer expects something else, including an empty string if you accept that risk.

It is kept, under a #text key, but the order is lost. An XML element may contain text, then a child element, then more text, and the sequence is significant to anyone reading it; JSON has no way to express that interleaving, so the text is gathered into a single string on one key and the elements sit beside it. Documents that are really narrative markup convert badly for this reason, and documents that are rows and records convert well. Neither the tool nor any other can preserve information JSON cannot hold.

It depends on who reads the result. The default — object for one, array for many — is what most conventions do and gives the shortest JSON, but it changes the shape of the data as soon as a second item appears, so downstream code that does items.map(...) works today and throws tomorrow. Switching on always-array makes the shape constant at the cost of a little noise, and that is usually the safer choice for anything that is genuinely a list. It is a design decision about your consumer, not a property of XML.

It checks that it is well-formed, which means the syntax is correct: tags are balanced, quotes are closed, text does not contain a stray ampersand. That is a different thing from valid, which in XML means conforming to a schema or a DTD that says which elements and attributes are allowed where. The tool will not validate against a schema, and a document that passes here can still be wrong in the sense a schema describes.

The namespace prefix is kept as part of the element name, so atom:entry arrives as the key atom:entry rather than entry. That preserves the distinction between two prefixes binding to different namespaces, and it avoids inventing a resolution rule. What it does not do is expand the prefix to the namespace URI or record the xmlns attributes separately, so if your consumer needs the full namespace information, that is something this conversion does not carry and you would need a format that does.

Not with this tool. Going back is genuinely harder, because JSON carries no record of which keys were elements, which were attributes and what order the children came in, and a converter has to guess or be told. Where round-tripping matters, keep the original XML as the source of truth and treat the JSON as a projection of it. That is also the sane arrangement if the document is edited: convert on the way out, never on the way back in.

Related tools

  • JSON Viewer
  • JSON Formatter
  • CSV to JSON Converter
  • JSON Diff
  • XML Sitemap Generator

Written and maintained by Md. Nur Hossain Repon.

NHRepon


Md. Nur Hossain Repon expert in NextJS, React, React Native and Flutter. He is a full-stack web and mobile application developer with 5+ years of experience and a passion for building innovative and robust application. Also, he has a strong background in developing high-quality web and mobile applications using the latest technologies and frameworks.
Let's build something amazing together 🚀

Quick Links


  • About
  • Projects
  • Services
  • Contact
  • Posts
  • Products
  • Privacy Policy
  • Terms of Service
  • Tools
  • Smart Life Hubs

Newsletter


We respect your privacy. Unsubscribe anytime.

Connect


© 2026 NHRepon. All rights reserved.

Build v1.5.4+56.73c4a90