XML to JSON Converter
Convert XML documents into clean, structured JSON directly in your browser.
Source Payload (XML)
UTF-8 · XML 1.0
10 lines·265 chars·265 B
Parsed JSON Result
Output Format
21 lines·393 B·0.00ms
Valid XML
- Zero Server TransmissionYour XML documents are processed exclusively in your browser memory. Data never touches remote servers.
- Predictable Structural MappingXML attributes, nested nodes, repeated sibling tags, and CDATA blocks are deterministically mapped to JSON structures.
- Real-Time XML ValidationMalformed syntax, unclosed tags, and character errors are pinpointed with precise line and column numbers.
Technical Foundation
Understanding XML → JSON Mapping
XML and JSON represent hierarchical data using fundamentally different tree models. ToolPorta maps XML nodes into clean, idiomatic JSON objects according to predictable rules.
Unlike XML, JSON has no native concept of attributes or duplicate object keys. ToolPorta maps XML attributes with an '@' prefix and automatically vectorizes repeated sibling tags into JSON arrays.
| XML Concept | JSON Representation | Example Mapping |
|---|---|---|
| Element with Text | String Key/Value | <name>Ali</name> → "name": "Ali" |
| XML Attributes | @ Prefix Property | <user id="12"> → "@id": "12" |
| Repeated Elements | JSON Array | Multiple <tag> → "tag": ["A", "B"] |
| Attributes + Text | @attr and #text | <price cur="MAD">100</price> → "#text": "100" |
| Namespaces | Qualified Key | <soap:Envelope> → "soap:Envelope": { ... } |
| CDATA Blocks | Unescaped String | <![CDATA[raw]]> → "raw" |
Sample Conversion Contract
Input XML Document
<user id="42" active="true">
<name>Yassine</name>
<tag>developer</tag>
<tag>morocco</tag>
</user>Resulting JSON Object
{
"user": {
"@id": "42",
"@active": "true",
"name": "Yassine",
"tag": [
"developer",
"morocco"
]
}
}Want to convert XML to JSON without losing attributes, mixed text, or array structures?
Code Reference
Developer Implementation Guides
Production snippets for parsing and converting XML to JSON across standard runtimes.
// Node.js & Browser via fast-xml-parser
import { XMLParser } from "fast-xml-parser";
const xmlData = '<user id="42"><name>Yassine</name></user>';
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "@",
textNodeName: "#text"
});
const jsonObj = parser.parse(xmlData);
console.log(JSON.stringify(jsonObj, null, ));View implementation guidesXML 1.0
Knowledge Base
Frequently Asked Questions
Attributes are converted into object properties prefixed with an '@' character (for example, id="42" becomes "@id": "42"). If an element contains both attributes and inner text, the text is captured under the "#text" key.
By default, namespace prefixes (such as <soap:Envelope> or <xmlns:atom>) are preserved as part of the JSON object key. You can toggle namespace stripping in the Advanced Options.
No. All parsing, validation, and JSON generation runs locally in your browser using fast-xml-parser and Web APIs. No network requests are made.
XML values are inherently text. Auto-converting strings like "0123" or "1.00" into numbers can cause data loss or strip leading zeros. You can enable 'Infer numbers & booleans' in Advanced Options if you prefer typed primitives.
The parser performs strict syntax validation before parsing. If a tag is unclosed or mismatched, exact line and column numbers are reported in the toolbar. DTD and DOCTYPE declarations are explicitly rejected for security.