Drag-n-Drop
to upload your archive
XML to JSON Converter
Convert complex XML files to JSON instantly
Simplify the data conversion process with our easy-to-use online XML to JSON Converter. Whether you're a developer, data analyst, or someone working with different data formats, our tool helps you quickly and accurately convert XML data into JSON format, making it easier to integrate, manipulate, and use in modern applications.
-
Accurate XML to JSON conversion
Our XML to JSON Converter accurately transforms your XML data into JSON format, preserving the structure, attributes, and content. This feature guarantees that your converted data is ready for use in modern applications, APIs, or data analysis processes.
-
Support for complex XML structures
Whether your XML data contains simple elements or complex nested structures, our converter handles it all. The tool efficiently processes attributes, nested elements, and mixed content, ensuring that the JSON output mirrors the complexity of the original XML data.
-
Secure and private processing
Your privacy is our priority. The XML to JSON Converter processes your XML data directly in your browser, meaning your files are not stored on any servers. This ensures that your data remains confidential and secure throughout the conversion process.
How to use the XML to JSON converter
-
1
Paste or Upload Your XML Data: Enter your XML data directly into the converter's text area or upload your XML file.
-
2
Click 'Convert': The tool will instantly generate the corresponding JSON output.
-
3
Copy or Download the JSON: Once the conversion is complete, you can copy the JSON or download the file for immediate use in your applications.
Supported file types
Open a file from your computer, drag one in, or paste your XML. The converter accepts:
The conversion runs entirely in your browser, so your XML never leaves your device. You can also paste data directly instead of opening a file, then copy or download the JSON.
Converting a different format? Static.app has a matching tool:
How to convert XML to JSON in code
The converter at the top of this page is the fastest route for a one-off file. It pretty-prints the result, so it doubles as an XML to JSON formatter. When the same conversion has to run inside an application, a build step or an integration flow, use the entry for your stack below: Python, Java, C#, Node.js, Power Automate, WSO2, or the command line. The first four are complete scripts, so you add the one dependency, point it at your file, and get JSON out. The last three are platform recipes rather than libraries.
Python: convert XML to JSON with xmltodict
Python has no XML to JSON conversion in the standard library, so nearly every project installs xmltodict. It maps each element to a dictionary key, which leaves the built-in json module to do the rest. It needs Python 3.9 or later and has no compiled dependencies.
pip install xmltodict
# python3 xml_to_json.py
import json
import xmltodict
with open("data.xml", "r", encoding="utf-8") as f:
doc = xmltodict.parse(f.read())
print(json.dumps(doc, indent=2, ensure_ascii=False))
Attributes come through with an "at" sign prefix by default. Pass attr_prefix="" to xmltodict.parse if you want them to look like ordinary keys, and force_list=("item",) if a single repeated element should still be a JSON array. Values stay strings, because xmltodict does not guess types.
Java: convert XML to JSON with org.json
In Java, XML to JSON is a one-call job: org.json ships an XML helper that converts a whole document in a single line. Add the dependency to your pom.xml or build.gradle first.
Maven: org.json:json:20250107 (or newer)
import org.json.JSONObject;
import org.json.XML;
import java.nio.file.Files;
import java.nio.file.Path;
public class XmlToJson {
public static void main(String[] args) throws Exception {
String xml = Files.readString(Path.of("data.xml"));
JSONObject json = XML.toJSONObject(xml);
System.out.println(json.toString(2));
}
}
Files.readString needs Java 11 or later. org.json infers types, so a numeric-looking element becomes a JSON number; the keepStrings overload turns that off. If you already use Jackson, jackson-dataformat-xml is the alternative: read the document with XmlMapper, then write it back out with ObjectMapper.
C#: convert XML to JSON with Newtonsoft.Json
System.Text.Json has no XML reader, so the idiomatic way to convert XML to JSON in C# is still Newtonsoft.Json, which ships a converter for XmlDocument and XDocument.
dotnet add package Newtonsoft.Json
using System;
using System.Xml;
using Newtonsoft.Json;
var doc = new XmlDocument();
doc.XmlResolver = null; // do not resolve external entities
doc.Load("data.xml");
string json = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented);
Console.WriteLine(json);
Qualify Formatting in full: System.Xml declares a Formatting enum too, so the bare name is ambiguous once both namespaces are imported. Setting XmlResolver to null keeps untrusted input XXE-safe.
Node.js: convert XML to JSON with the fast-xml-parser npm package
Search npm for "xml to json" and you get dozens of packages. The one most Node projects settle on is fast-xml-parser: it is quick on large documents and it lets you decide how attributes are named.
npm install fast-xml-parser
import { readFileSync } from "node:fs";
import { XMLParser } from "fast-xml-parser";
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "",
ignoreDeclaration: true
});
const doc = parser.parse(readFileSync("data.xml", "utf8"));
console.log(JSON.stringify(doc, null, 2));
Without ignoreDeclaration the XML declaration turns into a stray "?xml" key alongside your root element. The import syntax needs "type": "module" in your package.json. On CommonJS, swap the first two lines for const fs = require("node:fs") and const XMLParser = require("fast-xml-parser").XMLParser.
Power Automate: convert XML to JSON with an expression
Power Automate has no XML to JSON action, so the conversion lives in an expression. The xml() function turns your string into an XML value, and json() converts that value into a JSON object later actions can address with dot notation.
No connector or premium licence required
Compose (rename it: Compose_XML)
Inputs: <catalog><book><title>Dune</title></book></catalog>
Compose (rename it: Compose_JSON)
Expression: json(xml(outputs('Compose_XML')))
Output of Compose_JSON:
{ "catalog": { "book": { "title": "Dune" } } }
Type the expression without a leading "at" sign; the expression editor adds it. XML attributes arrive as keys carrying an "at" sign prefix, so reference them with bracket notation rather than a dot.
WSO2: convert XML to JSON with a messageType property
In WSO2, XML to JSON is a configuration change rather than a function call. Synapse holds the payload as XML internally, so you set the outgoing messageType and the JSON message formatter serializes it on the way out. Add these properties before the Respond or Send mediator.
JSON builder and formatter are enabled by default in deployment.toml
<inSequence>
<!-- payload arrives as XML, leaves as JSON -->
<property name="messageType" value="application/json"
scope="axis2" type="STRING"/>
<property name="ContentType" value="application/json"
scope="axis2" type="STRING"/>
<respond/>
</inSequence>
Set both properties. messageType picks the formatter, ContentType sets the header the caller sees. If you need to reshape the payload as well, run a PayloadFactory or Data Mapper mediator before them.
xmlstarlet: convert XML to JSON with yq on the command line
xmlstarlet cannot convert XML to JSON on its own: it is an XPath toolkit with no JSON output mode. The dependable pattern is to let xmlstarlet validate the document and narrow it to one subtree, then hand that to yq, which reads both formats.
brew install xmlstarlet yq | apt install xmlstarlet, then install yq from the mikefarah/yq releases
# 1. Validate, then pull out the single subtree you want
xmlstarlet val -e data.xml
xmlstarlet sel -t -c "/catalog" data.xml > catalog.xml
# 2. yq (mikefarah v4) does the XML to JSON step
yq -p xml -o json catalog.xml > catalog.json
# One-shot version when the whole file already has a single root
yq -p xml -o json data.xml
The yq in Debian and Ubuntu repositories is a different project (a jq wrapper) with no -p xml flag, so install mikefarah/yq from its releases page. Keep the xmlstarlet step to a single root element: selecting several nodes prints sibling fragments with no wrapper, and yq rejects that.
Expect the JSON shape to differ between tools. Each library names attributes its own way, fast-xml-parser turns numeric-looking text into JSON numbers where xmltodict leaves it as a string, and all of them (including the converter on this page) collapse a single occurrence of a repeated element into an object rather than a one-item array. Run a representative file through the online XML to JSON converter above to see how your document is shaped, then pick the library whose output is closest to what you need.
How Static.app's XML to JSON converter compares
Static.app converts XML to JSON privately in your browser and can then publish the file as a live website, while FreeFormatter, CodeBeautify, and ConvertSimple are strong pure converters that each do some things better than us.
| Static.app | FreeFormatter.com | CodeBeautify | ConvertSimple.com | |
|---|---|---|---|---|
| Processing locationFreeFormatter keeps data in transient RAM, not stored; ConvertSimple and Static.app never upload it. | In your browser | On their servers | Not stated | In your browser |
| Price and signupConvertSimple sells a $9 / 48-hour unlimited pass; the basic tool stays free. | Free, no signup | Free, no signup | Free, no signup | Free (optional paid pass) |
| Ads on the pageCodeBeautify shows ads; FreeFormatter loads analytics and third-party add-ons, not banner ads. | No ads | Analytics and add-ons | Ad-supported | No ads |
| Input methodsCodeBeautify wins here with load-from-URL. | Paste, open file, drag-drop | Paste, file upload | Paste, URL, file upload | Paste, file upload |
| Output actions | Copy, download | Copy, download | Copy, download, save online | Copy, download |
| Conversion optionsCompetitors win here; our converter has no indentation or minify settings. | Pretty-print only | Rich (indent, prefixes, encoding) | Indent, minify, URL input | Indent, minify, node names |
| Untrusted-XML safetyStatic.app blocks external entities and rejects DOCTYPE on the server path; others do not document this. | Blocks external entities (XXE-safe) | Not stated | Not stated | Not stated |
| Publish as a websitePure converters stop at the file; Static.app can host it live. | Yes (custom domain, free SSL) | No | No | No |
| Best for | Private convert, then host the file | Fine-grained convert options | Load-from-URL and minify | Private client-side convert |
Pick FreeFormatter or ConvertSimple when you want granular indentation and attribute settings, or CodeBeautify when load-from-URL and minify matter most. Choose Static.app when you want the conversion to stay in your browser, want external entities blocked so untrusted XML stays XXE-safe, and want to publish the JSON as a real website on a custom domain with free SSL right after converting.
Your JSON Files Deserve Reliable Static Hosting
Frequently asked questions
What is an XML to JSON converter?
An XML to JSON converter is an online tool that transforms XML data into JSON format. JSON is a lightweight data interchange format widely used in modern web applications and APIs. This tool makes it easy to convert complex XML files into JSON, which is often preferred for its simplicity and compatibility with various programming languages and tools.
Is the XML to JSON converter free to use?
Yes, our XML to JSON converter is completely free to use. You can access it from any device with an internet connection without any hidden costs or limitations.
Do I need to download or install anything to use the XML to JSON converter?
Our XML to JSON converter requires no downloads or installations. It is a fully online, browser-based tool, meaning you can start converting your XML data to JSON immediately without setting up any software.
How do I convert XML to JSON using the XML to JSON converter?
To convert XML to JSON, simply paste your XML data into the converter's text area or upload your XML file. Click the "Convert" button, and the tool will generate the corresponding JSON output. You can then copy the JSON or download the file for immediate use.
What does converting XML to JSON mean?
Converting XML to JSON means transforming your XML data into JSON format. This process is particularly useful for integrating data into modern web applications, APIs, and data analysis tools predominantly using JSON. The conversion simplifies the data structure and makes it easier to work with in various programming environments.
Does the XML to JSON converter support complex XML structures?
Yes, XML to JSON converter supports complex XML structures, including nested elements, attributes, and mixed content. The tool accurately processes these elements and converts them into the appropriate JSON format, preserving the hierarchical structure and data relationships found in the original XML.
Can I use the XML to JSON converter on mobile devices?
Absolutely! Our XML to JSON converter is fully responsive and works seamlessly on desktops, tablets, and smartphones. You can convert your XML data to JSON on the go without any issues.
Is my XML data safe and private?
Yes, your XML data is safe and private. Our XML to JSON converter processes your data directly in your browser, meaning it is not stored on any servers. This ensures that your work remains confidential and secure throughout the conversion process.
What are the benefits of converting XML to JSON?
Converting XML to JSON offers several key benefits: 1) Easier Data Manipulation: JSON is simpler and more flexible than XML, making it easier to manipulate and integrate into modern applications. 2) Better Integration: JSON is widely used in APIs, web services, and modern data interchange formats, making it easier to work with across different platforms and programming environments. 3) Improved Compatibility: JSON is compatible with most programming languages, allowing for seamless integration into various tools and systems. 4) Simplified Data Structure: JSON's lightweight nature simplifies the data structure, reducing the complexity found in XML and making the data more manageable.
How does the XML to JSON converter handle attributes and nested elements?
The XML to JSON converter accurately handles XML attributes and nested elements by converting them into corresponding JSON structures. Attributes in XML are typically converted to key-value pairs within the JSON object, while nested elements are preserved as nested objects or arrays within the JSON output. This ensures that the hierarchical structure and relationships in the original XML are maintained in the JSON format.
Can I learn about data formats by using the XML to JSON converter?
Yes, using the XML to JSON converter can be an educational experience. By converting XML to JSON, you can see how different data structures and elements are transformed between these two formats. This helps you understand the key differences between XML and JSON and how data is represented in each format.
How do I share the converted JSON data?
After converting your XML data to JSON, you can easily share the JSON output by copying it and sending it to others. If you want to host or share your JSON data online, consider using Static.app to host your JSON files. Static.app provides a simple platform to generate a public URL for your JSON file, making it easy to distribute and access.
What are the limitations of the XML to JSON converter?
While the XML to JSON converter is a powerful tool, it does have some limitations: 1) Focus on Standard XML: The converter is optimized for standard XML structures and may not fully support non-standard or custom XML formats. 2) Handling of Complex Mixed Content: In cases where XML contains complex mixed content (text interspersed with elements), the conversion to JSON might not perfectly replicate the original structure. 3) No Data Validation: The converter focuses on data transformation and does not validate the input XML or the output JSON for correctness or compliance with specific schemas. For validation, you would need to use additional tools designed for that purpose.
What is the best free XML to JSON converter, and how does Static.app compare?
There is no single best one; it depends on what you need. FreeFormatter gives you the most conversion settings (indentation, attribute prefixes, and encoding), CodeBeautify can load XML from a URL and minify the output, and ConvertSimple, like Static.app, converts entirely in your browser. Static.app's converter is free with no signup and no ads, converts client-side, blocks external entities so untrusted XML stays XXE-safe, and is the only one of these that can then publish your JSON as a live website on a custom domain with free SSL.
Does the XML to JSON converter send my file to a server?
No. Static.app converts your XML to JSON directly in your browser, so the data is not uploaded during conversion. This matches ConvertSimple, which also runs client-side, and differs from FreeFormatter, which processes on its servers (holding the data briefly in memory and not storing it). For extra safety our tool does not resolve external entities, which are the basis of XXE attacks, and its server fallback also rejects DOCTYPE declarations.
Can I publish the converted JSON as a website after converting?
Yes. After you convert XML to JSON, use the Host your JSON button to upload the file to Static.app and publish it as a live website on a custom domain with free SSL. Pure converter and formatter websites like FreeFormatter, CodeBeautify, and ConvertSimple let you copy or download the JSON but cannot host it for you.
How do I convert XML to JSON in Python?
Use xmltodict, the usual library for XML to JSON in Python 3. Install it with "pip install xmltodict", then call xmltodict.parse() on the file contents and json.dumps() on the result, which takes only a few lines. Attributes arrive with an "at" sign prefix, which you can change with attr_prefix, and force_list lets you keep a single repeated element as a JSON array instead of an object. Current releases need Python 3.9 or later. If you cannot add a dependency, xml.etree.ElementTree in the standard library will parse the document, but you have to walk the tree and build the dictionary yourself.
How do I convert XML to JSON in Java?
Add the org.json dependency to your pom.xml or build.gradle and call XML.toJSONObject(xmlString), then toString(2) on the returned JSONObject for indented output. It is a one-call conversion with no configuration. If your project already uses Jackson, the alternative is jackson-dataformat-xml: read the document with XmlMapper and write it back out with a plain ObjectMapper. Note that org.json infers types, so a numeric-looking element becomes a JSON number rather than a string, unless you use the keepStrings overload.
How do I convert XML to JSON in C#?
Use Newtonsoft.Json. Install it with "dotnet add package Newtonsoft.Json", load your file into an XmlDocument or XDocument, then call JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented). System.Text.Json has no XML reader, so this remains the standard approach in .NET. Qualify Formatting in full, because System.Xml declares an enum with the same name and the bare version is ambiguous. For untrusted input, set XmlResolver to null on the XmlDocument so external entities are never resolved.
Which npm package converts XML to JSON?
fast-xml-parser is the one most Node projects use. Run "npm install fast-xml-parser", create an XMLParser instance, and pass it your XML string. It handles large documents well and lets you control attribute handling through ignoreAttributes and attributeNamePrefix. Pass ignoreDeclaration so the XML declaration does not become a stray "?xml" key. Be aware that it converts numeric-looking text into JSON numbers by default. xml2js is the older alternative and works fine, but its API is callback or promise based and it is slower on big files.
How do I convert XML to JSON in Power Automate?
Power Automate has no XML to JSON action, so you do it with an expression. Put your XML in a Compose action, rename it Compose_XML, then add a second Compose with the expression json(xml(outputs('Compose_XML'))). The xml() function turns the string into an XML value and json() converts that value into a JSON object later actions can address with dot notation. No premium connector or licence is needed. Type the expression without a leading "at" sign because the editor adds it, and reference XML attributes with bracket notation, since they arrive as keys carrying an "at" sign prefix.
How do I convert XML to JSON in WSO2?
In WSO2 Micro Integrator, ESB and EI you never call a converter. Synapse holds the payload as XML internally, so you set the outgoing message type and the JSON message formatter serializes it on the way out. Add a property with name messageType and value application/json in the axis2 scope before your Respond or Send mediator, and set ContentType to the same value so the caller sees the right header. The JSON builder and formatter are enabled by default in deployment.toml. If you also need to reshape the payload, run a PayloadFactory or Data Mapper mediator before those properties.
Can xmlstarlet convert XML to JSON?
Not on its own. xmlstarlet is an XPath toolkit with no JSON output mode, so the dependable command line pattern is to let it validate the document and narrow it to one subtree, then pass that to yq, which reads both formats: run "xmlstarlet sel -t -c /catalog data.xml > catalog.xml" and then "yq -p xml -o json catalog.xml". If the file already has a single root, skip straight to yq. Note that the yq packaged in Debian and Ubuntu repositories is a different project with no -p xml flag, so install mikefarah/yq from its releases page. Keep the xmlstarlet step to one root element, because selecting several nodes prints sibling fragments with no wrapper and yq rejects that.