JSON to XML Converter
Transform JSON data into XML (Extensible Markup Language) format
JSON Input
XML Output
About JSON to XML Converter
Convert JSON data to XML (Extensible Markup Language) format with support for attributes, nested elements, and proper XML structure. Ideal for data interchange and configuration files.
Key Features
- XML Attributes: Use @ prefix in JSON keys to create XML attributes
- Nested Elements: Converts nested JSON objects to XML child elements
- Array Handling: Converts JSON arrays to multiple XML elements
- Custom Root Element: Specify your own root element name
- Pretty Printing: Optional formatted output with indentation
- XML Declaration: Include or exclude XML declaration header
- Name Sanitization: Automatically fixes invalid XML element names
- Special Character Escaping: Properly escapes XML special characters
How to Use
- Input JSON Data: Paste your JSON or upload a .json file
- Configure Options: Set root element, formatting, and attribute preferences
- Review Output: The XML output updates automatically
- Copy or Download: Use the Copy or Download button to save your .xml file
- Use in Applications: Import the XML into your application or system
Example Conversion
JSON Input:
{
"@version": "1.0",
"catalog": {
"@name": "Products",
"product": {
"@id": "1",
"name": "Laptop",
"price": 1299.99,
"inStock": true
}
}
} XML Output:
<?xml version="1.0" encoding="UTF-8"?>
<root version="1.0">
<catalog name="Products">
<product id="1">
<name>Laptop</name>
<price>1299.99</price>
<inStock>true</inStock>
</product>
</catalog>
</root> Attribute Handling
Use the attribute prefix (default: @) in JSON keys to create XML attributes:
- JSON: {\"@id\": \"123\", \"name\": \"Item\"}
- XML: <element id="123"><name>Item</name></element>
Array Conversion
JSON arrays are converted to multiple XML elements with the same name:
- JSON: {\"items\": [1, 2, 3]}
- XML: <items><item>1</item><item>2</item><item>3</item></items>
XML Syntax Elements
- Declaration: <?xml version="1.0" encoding="UTF-8"?>
- Elements: <element>content</element>
- Attributes: <element attr="value">
- Self-Closing: <element /> for empty elements
- Comments: <!-- comment -->
- CDATA: <![CDATA[content]]> for special content
Data Type Mapping
- String: JSON strings → XML text content
- Number: JSON numbers → XML text (1299.99)
- Boolean: JSON true/false → XML text (true/false)
- Null: JSON null → Self-closing element <element />
- Array: JSON arrays → Multiple XML elements
- Object: JSON objects → Nested XML elements
Common Use Cases
- Data Exchange: Convert JSON API responses to XML format
- Configuration Files: Create XML config files from JSON
- SOAP Services: Generate XML for SOAP web services
- RSS/Atom Feeds: Create feed XML from JSON data
- Legacy Systems: Interface with XML-only systems
- Data Migration: Convert JSON data to XML for import
XML Name Rules
The converter automatically sanitizes invalid XML names:
- Valid Characters: Letters, digits, hyphens, underscores, periods
- Must Start With: Letter or underscore (not digit)
- Invalid Characters: Replaced with underscores
- Reserved Names: xml, XML, etc. are reserved
Special Character Escaping
XML special characters are automatically escaped:
- & → &
- < → <
- > → >
- " → "
- ' → '
Best Practices
- Use Attributes: Use @ prefix for XML attributes in JSON
- Valid Names: Ensure JSON keys are valid XML element names
- Pretty Print: Enable for human-readable XML
- Root Element: Choose a meaningful root element name
- Validate Output: Test XML in your target application
- Namespace Support: Add namespaces manually if needed
Privacy & Security
All conversions happen locally in your browser. Your JSON data is never uploaded to any server, ensuring complete privacy and security.
