How to Convert JSON to XML and XML to JSON Locally
The JSON vs XML Debate: Why Both Formats Still Matter
Developers in the 2010s declared XML "dead" as JSON rose to prominence with REST APIs and JavaScript applications. In practice, XML is very much alive in 2025 — and shows no signs of going away:
- Enterprise systems — SAP, Oracle ERP, legacy banking, healthcare (HL7 FHIR), and government systems frequently use XML as their primary data format
- SOAP web services — thousands of enterprise web services use SOAP (Simple Object Access Protocol), which is XML-based. Interoperating with these requires XML handling.
- Configuration files — Maven (pom.xml), Spring (applicationContext.xml), Android layouts, and Microsoft Office documents (DOCX, XLSX) are all XML internally
- RSS and Atom feeds — news feeds, podcast directories (Apple Podcasts, Spotify), and many content syndication systems use XML-based formats
- SVG graphics — Scalable Vector Graphics are XML files, and manipulating SVGs programmatically requires XML tools
- XHTML and older web standards — some strict web systems still require XHTML rather than HTML5
When a modern JSON-native application needs to talk to an XML-native system, conversion is necessary. Getting the conversion right requires understanding the structural differences between these formats.
Structural Differences: JSON vs XML
JSON and XML represent data fundamentally differently:
- JSON uses key-value pairs, arrays, and nested objects. Data types are explicit: strings, numbers, booleans, null, arrays, objects.
- XML uses nested elements with text content and attributes. Everything is text by default; types must be inferred or schema-validated. XML also supports attributes (metadata on elements) and namespaces (scoping element names).
This means JSON-to-XML conversion requires decisions about mapping:
- JSON keys become XML element names (or attributes)
- JSON arrays require wrapping in an element since XML has no native array syntax
- JSON null can become an empty element or an xsi:nil attribute
- JSON numbers and booleans must be converted to text strings (XML has no native number type without schema)
JSON to XML: The Standard Mapping Rules
Here is a JSON object and its XML equivalent using common mapping conventions:
JSON:
{
"person": {
"name": "Alice",
"age": 30,
"email": "alice@example.com",
"addresses": [
{"type": "home", "city": "New York"},
{"type": "work", "city": "Chicago"}
]
}
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<person>
<name>Alice</name>
<age>30</age>
<email>alice@example.com</email>
<addresses>
<address type="home">
<city>New York</city>
</address>
<address type="work">
<city>Chicago</city>
</address>
</addresses>
</person>
Handling JSON Arrays in XML: The Key Challenge
JSON arrays have no direct equivalent in XML — XML elements can simply repeat. This creates an ambiguity when converting back from XML to JSON: are sibling elements with the same name an array, or separate distinct elements?
Different conversion conventions handle this differently:
- BadgerFish convention: JSON arrays map to an object key containing an array:
{"address": [{"$": "..."}]} - Parker convention: JSON objects map directly to XML elements; arrays are expanded as repeated sibling elements
- Mapped convention: use a wrapper element with a common child element name:
<addresses><item>...</item></addresses>
TinyWeb's JSON to XML converter uses the wrapped-item convention by default (most common in enterprise XML) with an option to select alternative conventions.
XML Attributes vs Elements: A Critical Decision
One of the most important decisions in JSON-to-XML conversion is whether JSON properties should map to XML attributes or XML child elements:
- XML attributes:
<user id="123" role="admin">— typically used for metadata, identifiers, and short scalar values - XML child elements:
<user><id>123</id><role>admin</role></user>— typically used for content data and nested structures
Many enterprise XML schemas expect specific properties as attributes. TinyWeb's converter allows you to specify which JSON keys should be rendered as XML attributes using a prefix convention (e.g., keys starting with "@" or "-" become attributes).
XML to JSON: Reverse Mapping
Converting XML back to JSON introduces its own challenges:
- Attributes — XML element attributes have no direct JSON equivalent; they are typically mapped to special keys like
"@type"or"_type" - Mixed content — XML elements can contain both text content and child elements simultaneously (
<p>Hello <strong>World</strong></p>); this is very hard to represent cleanly in JSON - Namespaces — XML namespace prefixes (
xsi:type) require stripping or mapping to JSON key conventions - CDATA sections — XML CDATA blocks (
<![CDATA[...]]>) containing unescaped HTML or code need to be preserved as strings - XML Declaration — the
<?xml version="1.0" encoding="UTF-8"?>header is metadata with no JSON equivalent
Using TinyWeb's JSON to XML Converter
- Go to TinyWeb JSON to XML
- Paste your JSON into the input area or upload a .json file
- Configure conversion options: root element name, array item element name, indent size
- Click Convert — the formatted XML output appears instantly
- Validate, copy, or download the result
Validating XML Output
After conversion, you should validate the XML output to ensure it is well-formed:
- All opening tags must have matching closing tags
- Attribute values must be quoted
- Special characters (&, <, >, ") must be escaped as XML entities
- The document must have exactly one root element
TinyWeb's converter automatically escapes special characters and ensures well-formed XML output. You can further validate against an XSD schema using an XML validator tool if your target system requires schema compliance.
Real-World Use Cases for JSON-XML Conversion
- SOAP API integration: your modern Node.js app receives JSON from a frontend; you must convert it to a SOAP XML envelope to call a legacy insurance or banking API
- Healthcare data exchange: HL7 FHIR supports both JSON and XML; converting between them is standard in healthcare integration layers
- Android resource files: converting JSON configuration to Android strings.xml or layout XML
- RSS feed generation: converting a JSON blog post database to RSS 2.0 XML format for syndication
- Excel/Office data: Microsoft Office Open XML (DOCX, XLSX) uses XML internally; converting JSON data structures to Office XML for programmatic document generation
Conclusion: JSON-XML Conversion Requires Careful Structural Mapping
Converting between JSON and XML is not simply a syntax change — it requires understanding the semantic differences between the two formats and making deliberate decisions about how arrays, attributes, and types map between them. TinyWeb's JSON to XML and XML to JSON converters handle the full complexity of this mapping with sensible defaults and configurable options, all running locally in your browser so sensitive business data never touches a server.