XML to JSON Converter
Convert XML documents to JSON with attribute handling and configurable parsing options
Input & Settings
JSON Output
Converted JSON will appear here
Analysis & Stats
Conversion statistics will appear here
About this tool
This tool converts XML documents into JSON objects using a robust client-side parser. It preserves element nesting, handles attributes (prefixed by default with @_), parses numbers and booleans, and trims whitespace. Use it to bridge XML-based APIs, config files, or legacy data into modern JSON workflows — all processing happens locally in your browser, nothing is uploaded.
Examples & Use Cases
Simple XML to JSON
<!-- XML Input -->
<person>
<name>John Doe</name>
<age>30</age>
<active>true</active>
</person>
// JSON Output
{
"person": {
"name": "John Doe",
"age": 30,
"active": true
}
}A basic XML element with text content is converted to a nested JSON object. Numeric and boolean values are parsed automatically.
XML with Attributes
<!-- XML Input -->
<book id="123" category="fiction">
<title lang="en">The Great Gatsby</title>
<year>1925</year>
</book>
// JSON Output
{
"book": {
"@_id": 123,
"@_category": "fiction",
"title": {
"@_lang": "en",
"#text": "The Great Gatsby"
},
"year": 1925
}
}Attributes are prefixed with @_ by default so they never collide with child element names. Text alongside attributes is nested under #text.
Repeated Elements Become Arrays
<!-- XML Input -->
<library>
<book><title>Book 1</title></book>
<book><title>Book 2</title></book>
</library>
// JSON Output
{
"library": {
"book": [
{ "title": "Book 1" },
{ "title": "Book 2" }
]
}
}Sibling elements with the same tag name are automatically grouped into a JSON array — the natural representation for repeated XML elements.
Examples
Convert a simple XML document
<config>
<database host="localhost" port="5432" />
<debug>true</debug>
</config>{
"config": {
"database": {
"@_host": "localhost",
"@_port": "5432"
},
"debug": true
}
}With default settings, XML attributes get an @_ prefix and the text node becomes the property value. Boolean strings are parsed to true.
Disable attribute prefix and number parsing
<item id="42" price="9.99">Book</item>{
"item": {
"@_id": "42",
"@_price": "9.99",
"#text": "Book"
}
}With parseAttributeValue false, id and price stay as strings even if they look numeric. The element's text node is available as #text when textNodeName is set.
About this tool
XML to JSON Converter transforms a well-formed XML document into its equivalent JSON representation entirely in your browser. It uses fast-xml-parser to parse and rebuild the document, and XMLValidator to check well-formedness before attempting conversion.
Configurable options let you control how attributes, text nodes, number parsing, boolean parsing, whitespace trimming, and output indentation are handled, so the output matches the schema your application expects.
Everything runs client-side — no XML is uploaded to any server.
How to use
Paste or load XML
Paste your XML into the input area, load a sample, or upload an .xml or .txt file.
Check well-formedness
The tool validates the XML with XMLValidator first. If the input has mismatched tags or other syntax errors, it reports the error with a line number instead of producing output.
Adjust conversion options
Toggle attribute prefix (default @_), number parsing, boolean parsing, whitespace trimming, and the indent size (1–8 spaces).
Copy or download the JSON
Copy the formatted JSON output or download it as a .json file.
Use cases
Migrating XML config to JSON
Turn a legacy XML configuration into a JSON file your modern application can read without rewriting it by hand.
Debugging XML API responses
Paste a raw XML response from a SOAP or legacy REST endpoint and read it as structured JSON instead of scanning tags.
Preparing test fixtures
Convert XML-formatted test data into JSON fixtures for tools like Jest or testing libraries that consume JSON.
Common mistakes
Mistake:Forgetting that text-only elements become the property value directly.
Fix:An element with no children but only text, like <name>Ada</name>, becomes { "name": "Ada" }. Mixed content (text and child elements) puts the text in the configured textNodeName key.
Mistake:Not checking whether the parser is in cdataTagName mode when CDATA sections are present.
Fix:CDATA sections are treated as text nodes by default. If your XML uses CDATA for raw character data, the output includes it as-is inside the text node — verify the parser settings match your input.
Frequently asked questions
Related guides
References & standards
Related tools
Driver's License Generator
Generate driver's license numbers in the correct format for 21 countries and all 50 US states, plus a format and Luhn validator — test data only, runs in your browser.
Address Generator
Generate realistic addresses in the correct format for 21 countries — single-line, multi-line, JSON or HTML — plus a postcode validator. Test data only, runs in your browser.
Phone Number Generator
Generate phone numbers in the correct format per country — mobile, landline and toll-free — in international, national, raw or tel: format, plus a validator. Test data only.
Markdown to HTML Converter
Convert Markdown to clean HTML with GitHub-Flavored Markdown, syntax highlighting, and optional sanitization
Docker Run to Compose Converter
Convert a docker run command into a docker-compose.yml service definition with full flag support
GitHub Actions YAML Generator
Generate GitHub Actions workflow YAML with triggers, jobs, and steps through a visual form