24 converter Units · Currency · Files

Convert XML to JSON Extensible Markup Language ↔ JavaScript Object Notation Free Online Secure

Drop your XML file in and take away JSON. It is read and written here, in your browser, so the file never leaves your device — and what the crossing keeps, and what it cannot, is written out below rather than left for you to discover.

Convert your file

Drop your XML file here, or choose one.

Your file never leaves this device. Everything runs in your browser.

About this converter
What it keeps Element names, their nesting, their attributes and their text. An attribute keeps its name with an @ in front; text that shares an element with child elements is kept under #text, because there is nowhere else to put it.
What it cannot do XML holds an idea JSON has no word for: elements are ordered and may repeat. A name that appears once becomes a value and a name that appears twice becomes an array, so reading the result back does not always give the same XML. Comments, processing instructions and the XML declaration are not part of the data and do not come across.
Where it runs In your browser. Nothing is uploaded, so there is nothing to delete afterwards.

Nothing uploaded

Convert from XML

Convert to XML

Where these formats come from

CSV is the oldest and the least standardised: a table written as lines of text, in use since the 1970s and only described in writing in 2005, by which time every program had already decided for itself what the separator was and when to put quotation marks. XML grew out of SGML in 1998 for documents that must carry strict structure and be checked against a schema. JSON was pulled out of JavaScript by Douglas Crockford around 2001, deliberately stripped down to objects, arrays, numbers and strings — and that minimalism is why it took over the web. YAML is its readable cousin, where indentation does the work that brackets do elsewhere. The one thing that matters when converting between them: CSV is flat, a grid of rows and columns, while JSON, XML and YAML are trees.

Where you meet them

CSV is what a spreadsheet exports and what an accountant, a shop platform or a bank statement will hand you. JSON is what web services speak and what configuration files are increasingly written in. XML survives in older enterprise systems, in invoicing standards and inside the office formats themselves. YAML is where humans write settings by hand. Converting between them is the daily work of moving data from where it was produced to where it is needed.

Questions people ask

My CSV opened as one column in Excel. Why?

Because your spreadsheet expected a different separator. Excel follows the list separator of the computer's regional settings, which is a semicolon anywhere the comma is already the decimal mark — that is, most of continental Europe. A file separated by commas then looks like a single column of text. Use the import dialogue and state the separator explicitly, rather than double-clicking the file. The same regional setting is why 3.5 sometimes arrives as a date.

Why can't my nested JSON become a tidy spreadsheet?

Because a spreadsheet is flat and JSON is a tree. A row can hold one value per column; a JSON object can hold a list inside a field inside another list. Converting means choosing how to flatten that: either joining nested names into one long column heading, or repeating the parent row once for each child. Both are compromises, and neither can be undone automatically — which is why going back from the spreadsheet to the original shape usually needs a human decision.

Does the file lose quality?

It depends on what the two formats can hold. Converting between formats that store the same thing — a PNG to a BMP, a WAV to a FLAC — loses nothing. Converting into a format that throws information away to save space, such as JPEG or MP3, loses a little every time, and converting back does not bring it back. Where a choice exists, this page errs towards keeping the original quality rather than making the smallest file.

Is my file uploaded anywhere?

No. The conversion happens inside your browser, on your own machine; the file never leaves it and there is no server here that could receive it. That is why a large file is limited by your own memory rather than by an upload, and why nothing you convert can appear in anybody's logs — including ours. The audio and video tools do fetch their conversion engine from this site the first time you use them, some thirty megabytes once; after that the work still happens entirely on your machine.

Why people convert XML to JSON

XML is the elder statesman of structured data. For more than twenty years it has carried configuration files, product feeds, invoices, sitemaps, news feeds, exports from accounting programs and the answers of older web services. It is precise and verbose, written in tags that open and close. JSON is its younger rival: lighter, easier to read and the natural language of modern web code, where a program can use it with almost no preparation. When a feed or an export arrives as XML and the thing that will use it speaks JSON, a conversion is needed. That is why people convert XML to JSON: they have data in the older form, and the new tools want the newer one.

The situations are common. A developer who must read the answer of an older service in a modern script. A shop owner who has a product feed in XML and a platform that imports JSON. A data analyst who wants to look at a large export in a tool that handles JSON. A student who needs to make sense of a file full of angle brackets. In every case the information is there, and what is missing is only a more convenient form.

This page converts XML to JSON in your browser. Your file is read and written here, so it never leaves your device, which matters for invoices, customer data and anything else private. And the page tells you in advance what the crossing keeps and what it cannot, rather than leaving you to discover it. XML holds an idea that JSON has no word for, and understanding it will save you surprises. Below you will find how the conversion works and what to expect.

How the conversion works

Elements become keys, nesting becomes nesting

Your XML is read inside your browser. Element names become keys, and elements inside elements become objects inside objects, so the nesting of the XML is the nesting of the JSON. The structure you see in the tags is the structure you get in braces.

Attributes keep their name with an @

XML elements can carry attributes, small pieces of data written inside the opening tag. JSON has no attributes, so each one is kept as a key of its own, with an @ in front of the name. An element such as a book with an attribute id will give a key @id beside the keys of its children. The @ makes it clear which keys came from attributes and which from elements.

Text beside child elements

Text that shares an element with child elements is kept under #text, because there is nowhere else to put it. This is rare in data files and common in documents that mix prose with markup. The key #text holds the text, and the other keys hold the children.

What is kept

Element names, nesting, attributes and text

Element names, their nesting, their attributes and their text are all kept. The information in the data is in the JSON, in a form that programs can walk through.

The order of what appears once

Elements keep the order in which they were written when they are different, so a record that lists a title, an author and a date shows them in that order.

Text exactly

The text of each element is kept as written, including spaces inside it and accented letters, symbols and characters from other alphabets.

What you should know before you convert XML to JSON

Repeated names become an array

XML holds an idea that JSON has no word for: elements are ordered and may repeat. A name that appears once becomes a value, and a name that appears twice becomes an array. So a list with three item elements becomes an array of three, but a list with a single item becomes just a value, not an array of one. This means that reading the result back does not always give the same XML. A program that reads the JSON should be ready for both forms where a list might be short.

Comments, processing instructions and the declaration are dropped

Comments, processing instructions and the XML declaration are not part of the data and do not come across. The note a developer left in a comment, the line at the top that states the version and the encoding, and instructions meant for a particular program disappear. The data itself remains.

Everything is text

XML has no types: every value in the tags is text. The numbers, dates and flags in your XML arrive as the text that was written. The program that reads the JSON should interpret them according to its own needs.

How to convert XML to JSON here

Add your file

Drop the XML file onto the page or pick it from your device. It is read inside your browser and is not uploaded.

Convert

Press the button. A file of ordinary size takes a moment. Leave the page open until it is done.

Download and check

Download the JSON and open it in a text editor. Look at the start and the end, and check that the keys are the names you expect and that attributes carry their @.

A closer look at XML and JSON

Two ways of writing a tree

Both XML and JSON describe a tree of values. XML writes it with tags that open and close, and allows attributes and mixed content. JSON writes it with braces and brackets, and knows only objects, lists, strings, numbers, booleans and null. They overlap well for data, such as records and settings, and overlap poorly for documents, such as a web page or a book, where text and markup are interleaved.

Why the round trip is not guaranteed

Going from XML to JSON loses a little: the order of repeated mixed elements, comments and the distinction between an attribute and an element, which is kept only through the @. Going back, you may therefore not get exactly the same XML. For data exchange, this rarely matters. For documents, it does, and it is better to keep the XML as the master.

Namespaces

XML names can carry a prefix that places them in a namespace, such as a vocabulary of a particular standard. Such names are kept as they are written, prefix included, so a key might read dc:title. They are not resolved or rewritten.

Common situations in detail

Product feeds and catalogues

Suppliers and marketplaces often offer feeds in XML. To use them in a modern script or to import them into a platform that takes JSON, convert XML to JSON and read the result.

Older web services

Services built in the era of SOAP and early APIs answer in XML. A script that wants to use their answer can work with JSON, which is easier to handle.

Configuration and settings files

Many programs store settings as XML. Converting a file to JSON lets you read it in a tool built for JSON, compare two versions or feed it to a script.

Feeds, sitemaps and exports

News feeds, sitemaps and exports from accounting or inventory programs are XML. A conversion gives you a form that is easier to search and to load in code.

Practical advice before you convert XML to JSON

Check that the XML is well formed

Every tag must close, and the file must have a single root element. If the page reports an error, open the file in an editor that highlights XML problems and fix the line it points to.

Know where lists may be short

If your XML has lists, remember that a list with one entry will become a value and not an array of one. Plan the code that reads the JSON to handle both cases.

Decide what to do with attributes

Attributes arrive as keys with an @. If your program expects them under other names, rename them after the conversion, or adjust the program.

Large files

Everything runs on your device, so a very large file needs memory. For files of many megabytes, use a computer, and split the data if the page struggles.

Questions people ask before converting

Why is one list an array and another a single value?

Because a name that appears once becomes a value, and a name that appears twice becomes an array. A list with one entry looks like a single value.

Where did my attributes go?

They are keys with an @ in front of the name, beside the keys of the child elements.

Where is the text that sits beside other elements?

Under the key #text, because there is nowhere else to put it.

Why are my comments gone?

Comments, processing instructions and the XML declaration are not part of the data and do not come across.

Is my file uploaded?

No. The conversion runs in your browser and the file never leaves your device.

Can I go back to XML?

Yes. JSON to XML writes a tree back as XML, though the round trip is not guaranteed to be identical.

Choosing wisely when you convert XML to JSON

JSON, YAML or a table?

JSON suits programs. For a configuration that people edit, JSON to YAML reads more comfortably after the conversion. If the XML is really a table of uniform records, you can follow with JSON to CSV or JSON to XLSX.

Keep the XML

The XML is the master. It holds the comments, the declaration and the exact order. Keep it, and treat the JSON as a convenient copy.

Think about the consumer

Look at what will read the JSON, and shape the work to suit it. A script that expects a fixed structure is easier to write if the XML is regular.

Getting a good result after the conversion

Validate the JSON in a viewer

Open the result in an editor that understands JSON and collapse the objects. If the structure looks like what you expect, it is sound.

Compare a few records with the source

Take a few records in the middle and check them against the XML. It takes a minute and tells you the conversion is faithful.

Minify for publishing

If the file will be loaded by a web page and is large, tools exist that remove whitespace and make it lighter. The data stays the same.

Preparing your XML so that it converts well

Keep the structure regular

When you convert XML to JSON, regular data converts best: the same elements in the same places, with lists always written as repeated elements. Irregular files produce irregular JSON, and the program that reads it must cope.

Avoid mixing text and elements where you can

Text beside child elements goes under #text. It is correct, but it makes the result harder to use. For data, keep text in the leaves, not between branches.

Test with a small piece first

If your file is large, take the first records into a test file and convert that. A quick look at the result shows whether the shape is what you expect.

Reading the JSON after you convert XML to JSON

Walk the structure, do not guess it

The shape of the result mirrors the shape of the XML, so the best way to understand it is to open both side by side. Find the root element, which becomes the top-level key, and follow one record down to its leaves. After you convert XML to JSON, this ten-minute walk saves hours of trial and error in code.

Write defensive code for lists

Because a single entry is a value and several entries are an array, the safest habit is to wrap what you read: if it is not an array, put it in one. A line of code at the start of the reader makes the rest simple, and your program no longer breaks on the day a feed contains only one product.

Handle attributes with care

Keys that begin with @ are attributes. Some tools do not like such names as property names, so you may prefer to rename them while loading. The meaning stays the same; only the label changes.

Do not edit the JSON as a substitute for the source

When the data changes, change the XML at its source, or have the system produce a new export, and convert XML to JSON again. Editing the copy leaves the two out of step.

Privacy and handling

Why local conversion matters for data

XML files often hold what is private: invoices, customers, orders, settings. Many online converters upload your file to a server, process it and send back the result, and for a while a copy lives on a machine you do not control. Here your own browser does the work, so the data stays on your device.

What happens when you leave

When you close the page, the converted file disappears from the browser, so download it first. Nothing about your data is kept.

If something goes wrong

The page says the XML is not valid

A tag may not close, or there may be two root elements, or a character that XML does not allow. Open the file in an editor that highlights XML errors and fix the line it points to.

The structure is not what I expected

Check for lists that have one entry, and for attributes and mixed text. They explain most surprises.

The page freezes with a large file

Everything runs on your device, and a large file needs memory. Try again on a computer, or split the data.

Related tools

The same family of tools covers the neighbouring jobs. To go back, use JSON to XML. For configuration files, JSON to YAML and YAML to JSON convert between those two. For tables, there are JSON to CSV, CSV to JSON, JSON to XLSX and XLSX to JSON.

A worked example

Say a supplier sends you a product feed as an XML file with 800 products, each with an id attribute, a name, a price and a list of categories. You drop the file here and press the button. A moment later you download a JSON with an array of 800 products. The id of each is a key @id, the name and the price are keys of their own, and the categories form an array. For the few products with a single category, the value is a plain string, and your import script handles both cases. The XML stays in your folder as the supplier's original.

A short checklist

Before converting

Check that the XML is well formed. Note where lists may be short. Keep the XML.

While converting

Stay on the page until the file is ready.

After converting

Open the JSON, check the keys, attributes and lists, and test it with the program that will read it.

Common mistakes

Assuming every list is an array

A list with one entry becomes a value. Write the reading code to accept both.

Expecting a perfect round trip

Do not rely on going from XML to JSON and back to give the same XML. Keep the original.

Forgetting that all values are text

XML has no types. Convert numbers and dates in the program that uses them.

Your data stays on your device

The conversion happens locally. Your file is read by your own browser, rewritten there and handed back as JSON. Nothing is uploaded, so no copy ends up on a server and nobody else can read it. For data with private content, that is the safe way to convert XML to JSON.

Summary

To convert XML to JSON here, drop the file and press the button. It is read and written in your browser, so the file never leaves your device. Element names, their nesting, their attributes and their text are kept. An attribute keeps its name with an @ in front, and text that shares an element with child elements is kept under #text, because there is nowhere else to put it. XML holds an idea that JSON has no word for: elements are ordered and may repeat. A name that appears once becomes a value and a name that appears twice becomes an array, so reading the result back does not always give the same XML. Comments, processing instructions and the XML declaration are not part of the data and do not come across.

Length & area Mass & volume Temperature Currency