When You Need to Convert Between JSON and XML
JSON and XML are both ways to structure data, but they live in different ecosystems. REST APIs almost always speak JSON. Enterprise systems — especially in finance, healthcare, and government — often still use XML (and SOAP). If you work at the intersection, you will eventually need to convert between them.
HarborConvert handles both directions: JSON → XML and XML → JSON, all in your browser.
JSON to XML: How the Mapping Works
JSON and XML have different structural models, so conversion always involves some interpretation:
- JSON objects become XML elements
- JSON arrays become repeated XML elements with the same tag name
- JSON strings/numbers/booleans become XML text content
- JSON keys become XML element names
Example input:
{
"user": {
"name": "Alice",
"age": 30,
"tags": ["admin", "editor"]
}
}
Becomes:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<name>Alice</name>
<age>30</age>
<tags>admin</tags>
<tags>editor</tags>
</user>
</root>
XML to JSON: Attributes vs. Elements
XML supports attributes (properties inside an opening tag) as well as elements. JSON has no equivalent concept. The converter maps XML attributes to a @attributes key by default:
<product id="42" status="active">
<name>Widget</name>
</product>
Becomes:
{
"product": {
"@attributes": { "id": "42", "status": "active" },
"name": "Widget"
}
}
Step-by-Step
JSON → XML
- Open the JSON to XML converter
- Paste or upload your JSON file
- Download the formatted XML output
XML → JSON
- Open the XML to JSON converter
- Paste or upload your XML file
- Download the JSON output
Practical Tips
- Validate first: Malformed JSON or XML will cause the converter to fail with a clear error message. Use a validator to check your input if the conversion doesn't work.
- Large datasets: For XML files with thousands of records, the conversion may take a moment. Both libraries are optimized for streaming-style processing in the browser.
- Namespaces: XML namespaces (like
xmlns:soap="...") are preserved in the output but may need manual cleanup if your target system doesn't expect them.