JSON-XML Converter - Convert JSON to XML & XML to JSON Online
Convert between JSON and XML formats bidirectionally with configurable attributes, namespaces, and formatting. 100% client-side, your data never leaves your browser.
Frequently Asked Questions
What is a JSON-XML converter?
A JSON-XML converter is a tool that transforms data between JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) formats. JSON uses curly braces, brackets, and key-value pairs, while XML uses hierarchical tags with attributes. Both represent structured data, but XML supports additional features like attributes, namespaces, and CDATA sections that have no direct JSON equivalent. This converter uses conventions (like @_ prefix for attributes and #text for text nodes) to enable bidirectional conversion while preserving as much information as possible.
How do I use this JSON-XML converter?
Select your conversion direction using the radio buttons: JSON → XML or XML → JSON. Paste your data into the input area, or click Sample to load example data. The conversion happens automatically in real-time as you type. Configure options as needed: attribute prefix, XML declaration, root element name, indentation. Review the converted output in the output area. Click the Copy button to copy the result, or use Download to save as a file. Use the Swap button to quickly reverse direction with your current data.
Is my data safe? Does it get sent to a server?
Your data is 100% safe and never leaves your browser. This converter uses the fast-xml-parser library running entirely in client-side JavaScript. No data is transmitted to any server, stored in any database, or logged anywhere. All parsing, validation, and conversion happens locally on your device. You can verify this by disconnecting from the internet — the tool works fully offline after the initial page load. This makes it safe for converting sensitive XML configuration files, API responses containing credentials, and enterprise data.
How are XML attributes handled during conversion?
XML attributes are mapped to JSON properties using a configurable prefix. By default, the prefix is @_, so an XML attribute like <book category="fiction"> becomes {"@_category": "fiction"} in JSON. You can change the prefix to @, -, or $ depending on your needs. When converting back from JSON to XML, properties with the configured prefix are automatically converted back to XML attributes. If an element has both attributes and text content, the text is stored under the #text key.
What happens to XML namespaces during conversion?
By default, namespace prefixes are preserved in the JSON output (e.g., <soap:Envelope> becomes {"soap:Envelope": ...}). You can enable the Strip Namespaces option to remove namespace prefixes, which simplifies the JSON output (e.g., <soap:Envelope> becomes {"Envelope": ...}). Note that stripping namespaces is a lossy operation — if you convert the JSON back to XML, the namespace information will be lost. Keep namespaces if you need lossless round-trip conversion.
Why does my JSON need a root element when converting to XML?
XML requires exactly one root element. If your JSON has a single top-level key (e.g., {"bookstore": {...}}), that key becomes the root element. However, if your JSON is an array (e.g., [{...}, {...}]) or has multiple top-level keys, the converter wraps the output in a root element (default name: root). You can customize the root element name in the options. This is a fundamental XML requirement, not a limitation of the tool.
What are the limitations of JSON-XML conversion?
The conversion between JSON and XML is not always perfectly lossless due to fundamental format differences. Key limitations include: (1) XML comments are lost when converting to JSON because JSON has no comment syntax; (2) XML processing instructions (except the declaration) are typically stripped; (3) XML mixed content (text interleaved with child elements) requires the #text convention which may feel unintuitive; (4) JSON key ordering may not be preserved (objects are unordered by spec); (5) XML CDATA sections are converted to regular text in JSON. For most practical use cases (API data, configuration files, data exchange), these limitations rarely cause issues.
Code Examples
// JSON to XML conversion using fast-xml-parser
const { XMLParser, XMLBuilder, XMLValidator } = require('fast-xml-parser');
function jsonToXml(jsonString) {
const parsed = JSON.parse(jsonString);
const builder = new XMLBuilder({
attributeNamePrefix: '@_',
textNodeName: '#text',
format: true,
indentBy: ' ',
ignoreAttributes: false,
});
return '<?xml version="1.0" encoding="UTF-8"?>\n' + builder.build(parsed);
}
function xmlToJson(xmlString) {
const validation = XMLValidator.validate(xmlString);
if (validation !== true) {
throw new Error(`Line ${validation.err.line}: ${validation.err.msg}`);
}
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: '@_',
textNodeName: '#text',
parseAttributeValue: true,
});
return JSON.stringify(parser.parse(xmlString), null, 2);
}
// Example
const json = '{"book":{"@_id":"1","title":"Hello"}}';
console.log(jsonToXml(json));
// <?xml version="1.0" encoding="UTF-8"?>
// <book id="1"><title>Hello</title></book>