Skip to content
Data2026-07-156 min read

Online XML/JSON Converter: Convert Between Data Formats

What Are XML and JSON

XML (eXtensible Markup Language) is a markup language for marking data, supporting attributes and namespaces.

JSON (JavaScript Object Notation) is a lightweight data exchange format using key-value pairs.

Comparison Example

XML:

<user id="1">
  <name>Alice</name>
  <email>alice@example.com</email>
  <bio><![CDATA[score: a < b]]></bio>
  <tags>
    <tag>developer</tag>
    <tag>admin</tag>
  </tags>
</user>

JSON (this site's defaults):

{
  "user": {
    "@id": "1",
    "name": "Alice",
    "email": "alice@example.com",
    "bio": {
      "#cdata": "score: a < b"
    },
    "tags": {
      "tag": ["developer", "admin"]
    }
  }
}

Attributes land on @id, CDATA under #cdata, and repeated siblings become arrays — the ToolVault converter defaults. You can turn attributes off or force every element into an array on the tool page.

XML vs JSON Comparison

FeatureXMLJSON
ReadabilityMediumHigh
File sizeLarge (tag redundancy)Small
Data types❌ All strings✅ Multiple types
Attribute support✅ Native⚠️ Convention-based
Namespace✅ Supported❌ Not supported
Comments✅ Supported❌ Not supported
Schema validation✅ XSD✅ JSON Schema
Web standardLegacyModern

Why You Need XML/JSON Conversion

  1. Web service migration: SOAP (XML) → REST (JSON) API upgrade
  2. Config file conversion: Legacy XML config → modern JSON config
  3. Data integration: Different systems use different formats
  4. RSS/Atom parsing: RSS Feed (XML) → JSON processing
  5. Office documents: .docx/.xlsx are XML-based, need JSON conversion
  6. Legacy system integration: New systems connecting to XML-based old systems

Common Conversion Challenges

ChallengeDescriptionWhat this tool does
Attributes vs elementsNo standard JSON form for attributesDefault @attr prefix; optional off
Repeated elementsSometimes one, sometimes manySibling repeats → arrays; force-array tags or wrap-all
Text / CDATAMixed content and raw fragments#text / #cdata; optional keep whitespace
NamespacesPrefixes enter key namesKeeps ns:tag literally — agree upstream
Malformed XMLMismatched tags silently acceptedWell-formed validation with line:col

How to Use an Online Tool

Using ToolVault's XML/JSON Converter:

  1. Paste XML and click “XML → JSON” (or the reverse with JSON)
  2. Toggle options: keep attributes, keep CDATA, wrap all elements as arrays, keep text whitespace
  3. For a stable array shape on only some tags, list local names under “Force-array tags” (e.g. role,item)
  4. On failure, read the line:col badge and context pointer instead of re-reading the whole blob
  5. Everything runs in the browser; nothing is uploaded

Note: conversion is button-triggered, not silent auto-detect, and there is no server-side streaming pipeline for huge files — sample and agree conventions first.

Conversion in Code

JavaScript (close to this site's defaults)

const { XMLBuilder, XMLParser } = require('fast-xml-parser');

// XML → JSON (validate — otherwise bad tags may pass silently)
const parser = new XMLParser({
  ignoreAttributes: false,
  attributeNamePrefix: '@',
  cdataPropName: '#cdata',
  textNodeName: '#text',
  processEntities: false,
});
const xml = '<user id="1"><name>Alice</name></user>';
const json = parser.parse(xml, true);

// JSON → XML
const builder = new XMLBuilder({
  ignoreAttributes: false,
  attributeNamePrefix: '@',
  cdataPropName: '#cdata',
  format: true,
});
const xmlStr = builder.build(json);

Python

import xmltodict
import json

# XML → JSON
xml_str = '<user id="1"><name>Alice</name></user>'
data = xmltodict.parse(xml_str)
json_str = json.dumps(data, indent=2)

# JSON → XML
data = {"user": {"name": "Alice"}}
xml_str = xmltodict.unparse(data, pretty=True)

Attributes, namespaces, and mixed content: the unsolvable triangle

Three XML features have no natural JSON home, and every converter picks different answers. Attributes: prefix conventions (@id) or child objects — pick one and stay consistent. Namespaces: ns:element flattens to keys or drops the URI (collisions follow); SOAP and enterprise schemas live here. Mixed content is hardest — JSON invents #text; enable “Keep text whitespace” when spacing matters. Document-heavy mixed XML usually should stay XML.

Array shape: why force-fold exists

Downstream TypeScript or JSON Schema often assumes tag: string[], but a single occurrence usually becomes a scalar tag: "admin" — and runtime breaks. Fix it three ways: guarantee repeats at the source, accept both shapes in consumers, or stabilize at convert time with force-array tags / wrap-all-arrays. Put that on the integration checklist.

DTDs, XXE, and why converters disable entities

XML parsers that resolve Document Type Definitions can be coerced into XXE: a crafted DTD reads local files or SSRFs internal endpoints. The converter keeps entity processing and external entities off; verify any tool you feed untrusted XML into does the same. A converter that happily resolves entities is a file-disclosure primitive aimed at its own environment.

Schema round-trip: when JSON schemas cannot express XML

XML Schema (XSD) expresses ordering (sequence), choice groups, and mixed content constraints that JSON Schema cannot — an XSD-to-JSON-Schema conversion is always lossy. Order-sensitive data degrades silently when objects lose element order. Before converting: does anything downstream depend on order, namespaces, or attributes? If yes, keep XML at the boundary.

A conversion checklist before you ship the mapping

  1. Decide attribute policy (@attr vs nested object) and document it for both directions
  2. List tags that must always be arrays — enable force-array / wrap-all on the XML/JSON converter
  3. Confirm whether whitespace and CDATA must survive (#text / #cdata)
  4. Reject untrusted XML that needs DTD/entity expansion — keep entities off
  5. Round-trip a golden fixture in CI; fail the build if key shape drifts

Skipping (2) is the most common production break: a one-item XML list becomes a JSON scalar on Tuesday and an array on Wednesday when a second item appears.

FAQ

How to Convert XML Attributes to JSON?

No single standard exists. This site defaults to @ for attributes (e.g. @id), #text for text, and #cdata for CDATA. Turn off “Keep attributes” on the tool page to drop them.

Does JSON to XML Lose Information?

Possibly. Arrays need element-name conventions; JSON types often become text in XML; without an attribute prefix, attributes and children misalign. Align naming and array shape before converting.

Why Did Bad Tags “Convert” Before?

Some parsers skip pair validation and rewrite mismatches quietly. This tool validates well-formedness and reports line:col so you can fix the document.

When to Use XML vs JSON?

Use XML for namespaces, strict Schema validation, and mixed document content (e.g. XHTML). Use JSON for Web APIs, config files, and frontend–backend exchange. Modern projects lean JSON, but plenty of boundaries still speak XML.

Triage notes

'The unsolvable triangle' admits that attributes, namespaces, and mixed content have no natural home in JSON and that every converter answers differently — so the rule given is not 'pick the right answer' but 'pick one answer and keep the whole pipeline consistent'. The array-shape section grabs a runtime bomb: an element that appears only once in XML becomes a scalar, and downstream code assuming tag: string[] detonates at runtime; pick one of the three remedies and write it into the integration checklist. The XXE section's line of persuasion is heavy — a converter happy to resolve entities is a file-disclosure primitive pointed at its own environment — and the well-formedness check corrects 'it converted before': some parsers skip pairing validation by default and silently rewrite mismatched closing tags, where this site chooses to error out with a line number.


This article is brought to you by ToolVault. More developer tools at the homepage.