Skip to content
Server-sideDeleted in 30 minutes

Convert XML to JSON

XML to JSON is a useful bridge when a structured document needs to enter an API, a JavaScript application, a configuration review, or a data-processing script. The converter reads ordinary XML nesting and produces a JSON representation that is easier to inspect with modern tooling. Repeated sibling elements are treated as collection-like data, while element attributes remain available in the resulting structure instead of disappearing with the angle-bracket markup. That makes this tool more useful than simply stripping tags, but it does not make XML and JSON identical models. Mixed text and child elements, namespaces, comments, processing instructions, schemas, and unusual vendor conventions may need a careful look after conversion. The built-in transform is a practical parser for ordinary nested elements and attributes, not an XSLT engine. It does not apply stylesheet templates, run XPath programs, validate an external schema, or fetch remote entities. Upload the XML you want to transform, inspect the JSON shape, and keep the original when a downstream system needs exact document fidelity.

Use this without the search next time. Prathom Workbench puts Prathom's tools in your toolbar.

Add to Chrome — free
XMLJSON

Drop your XML file here, or click to browse

Up to 50 MB. Deleted automatically after 30 minutes.

What it does

  • Nested XML elements represented as JSON data
  • Repeated sibling elements preserved as collection-like values
  • Ordinary element attributes retained in the JSON representation
  • Pure-code server conversion with no XSLT or remote resource fetching

How to use XML to JSON

  1. 1

    Add the XML document

    Upload an XML file containing the records or hierarchy you want to hand off. Use the actual source document rather than a URL; this converter works on the supplied file and does not retrieve remote entities, schemas, stylesheets, or linked assets.

  2. 2

    Review the structural mapping

    The pure-code transform reads ordinary nested elements, groups repeated siblings as collection-like values, and keeps element attributes in the JSON result. Check mixed content, namespaces, and empty elements because JSON has different rules for representing those XML features.

  3. 3

    Download and test the result

    Download the JSON file, format it in your target application, and test a representative record before replacing an established import. Keep the XML beside it when exact source reconstruction or schema validation is part of the workflow.

How it works

The transform reads the XML document as a tree rather than treating it as a bag of tags. Each ordinary element contributes a named value, and child elements become nested properties below their parent. When the same element name occurs repeatedly under one parent, the result can express that repetition as a collection-like JSON value. This is the part that makes an order, catalog, feed, or inventory file useful to code that expects arrays and objects instead of node traversal.

Attributes are a second source of information. They describe an element without being child elements, so the conversion keeps them in the generated representation rather than dropping them with the XML syntax. An identifier, language code, status flag, or unit can therefore travel with the value it qualifies. Empty elements and text-only elements are still cases worth checking because JSON has no single universal rule for whether an empty value should be null, an empty string, an empty object, or an absent property.

The operation is intentionally narrower than a document transformation system. It does not interpret an XSLT stylesheet, perform XPath selection, calculate totals, enforce an XSD, or contact a URL mentioned by the input. Namespaces and mixed content can carry meaning that a straightforward object model cannot show perfectly. Treat the downloaded JSON as a useful structural derivative, not as a promise that every XML document can be round-tripped byte for byte.

When you'd use this

This conversion is a good fit for a one-off inspection, a small migration, a fixture for a JavaScript test, or an integration handoff where the receiver already speaks JSON. It is also useful when a team wants to look at a vendor feed in a familiar tree viewer before deciding which fields deserve a formal mapping. The result gives developers a clearer starting point than manually replacing opening and closing tags.

It is less suitable as the final step for regulated interchange, signed XML, or documents whose meaning depends on whitespace, namespace URI, element order, comments, or mixed narrative content. Keep the source file, compare several real records, and add explicit validation in the application that consumes the JSON. That small discipline prevents a convenient inspection conversion from being mistaken for a complete schema migration.

Worked examples

Consider an inventory with three sibling item elements. JSON makes the repeated inventory entries natural to loop over, and the sku attribute remains useful for identifying each one. An order with one customer, one address, and several line elements similarly becomes a nested object with a line collection. In both cases, the conversion changes the container and access style; it does not decide how tax, currency, or missing fields should be interpreted.

Before wiring the result into a loader, inspect one record with an attribute, one repeated child, one empty element, and one text value. Those four checks reveal most mapping surprises early. If the consumer expects a specific property name or array path, write that mapping explicitly after conversion rather than assuming that a generic XML-to-JSON convention matches the receiving API.

Examples

A catalog with repeated product elements

catalog.xml containing catalog currency="USD" and three product elements with id attributes, names, and prices
catalog.json containing a catalog object, a collection-like product value, and retained product attributes

Repeated products are the important part of this result. A script can iterate over the collection instead of searching XML nodes, while the identifiers remain available for joins or update calls. Check the exact property names before hard-coding a production import.

A nested order sent to an API preparation step

order.xml containing customer details, a shipping address, and two nested item elements
order.json containing customer and shipping objects plus an item collection with quantities and prices

The nested shape stays visible, so code can address shipping fields and item values without manual tag scanning. The conversion is a representation change rather than business-rule mapping: totals, defaults, and API-specific field renames still belong in the next step.

Frequently asked questions

Does XML to JSON preserve attributes and repeated elements?

For ordinary XML, yes: the built-in representation keeps element attributes as data and treats repeated sibling elements as collection-like values rather than silently keeping only the last one. The precise property shape still deserves inspection, especially when a document mixes text, child elements, empty tags, namespaces, or vendor-specific conventions in the same record.

Is this XML to JSON converter an XSLT engine?

No. It is a pure-code structural transform for ordinary nested elements and attributes. It does not load an XSLT stylesheet, execute XPath templates, validate an XML Schema, resolve a remote entity, or apply domain-specific business rules. Use the result as a practical data handoff, and use a dedicated XML pipeline when stylesheet-driven document production is required.

What happens to mixed content and namespaces?

JSON can represent nested values, but it does not have XML's native distinction between ordered text fragments, element names with namespaces, attributes, and processing instructions. Ordinary records convert cleanly; mixed prose and child tags or namespace-heavy vocabularies may need manual review. Compare representative output with the consumer's expectations before automating a large batch.