Ttooleras
🔀

JSON to XML Converter

Converters

Convert between JSON and XML — for SOAP APIs, legacy integration, data migration. Free, private — all processing in your browser.

Advertisement

The JSON to XML Converter (and reverse XML to JSON) translates between the two major structured data formats. JSON dominates modern REST APIs; XML persists in SOAP web services, legacy enterprise systems, RSS/Atom feeds, and industry-specific formats (HL7, EDIFACT, FpML). Converting between them bridges old and new systems — modernizing SOAP APIs to speak JSON to frontend apps, or integrating with legacy XML-only backends. Supports attributes vs elements, namespaces, CDATA sections, arrays, nested objects, and round-trip conversion (JSON → XML → JSON preserves structure).

This conversion is not purely mechanical — XML has features JSON lacks (attributes, namespaces, mixed content, processing instructions) and vice versa. The tool uses common conventions: JSON properties prefixed @ become XML attributes, #text for text content, arrays become repeated elements. This is the convention used by popular libraries (Jackson XmlMapper, xml2js, DOTNET XmlSerializer). Output is valid, parseable XML or JSON — ready to send to target system.

JSON to XML Converter — key features

Bidirectional conversion

JSON to XML or XML to JSON. Toggle with one click.

Attribute vs element

@-prefix convention for attributes, regular keys for elements. Handles both correctly.

Namespace support

XML namespaces preserved in both directions.

CDATA section handling

Code or special characters wrapped in CDATA when appropriate.

Array representation

JSON arrays become repeated XML elements. Single vs multiple handled.

Text content with attributes

#text convention for element text alongside attributes.

Configurable conventions

Choose between different conventions: @attr vs _attr, #text vs $text.

100% client-side

Your data stays in browser. Safe for SOAP payloads with credentials.

How to use the JSON to XML Converter

  1. 1

    Paste input

    JSON or XML — tool auto-detects. Can be a snippet or full document.

  2. 2

    Choose direction

    JSON to XML or XML to JSON. Toggle as needed.

  3. 3

    Configure conventions

    Attribute prefix (@), text property name (#text), single vs array handling.

  4. 4

    Click Convert

    Output appears instantly. Verify structure is what you expected.

  5. 5

    Copy or download

    Paste into your application or save as .json/.xml file.

Common use cases for the JSON to XML Converter

Legacy integration

  • SOAP to JSON adapter: Wrap SOAP web service with JSON-speaking REST API. Convert XML responses to JSON for consumers.
  • Modernize XML APIs: Company has XML API. New mobile app wants JSON. Bridge with this converter.
  • Enterprise data exchange: Many enterprise systems (banking, healthcare, government) still use XML. Modern apps use JSON.
  • EDI/XML to JSON: Legacy EDI or XML industry formats to JSON for analytics.

API development

  • Accept both formats: REST API that accepts both JSON and XML for flexibility. Convert XML requests to JSON internally.
  • Content negotiation: Return JSON or XML based on Accept header. Single internal data, two output formats.
  • RSS/Atom to JSON: Feed aggregator converts RSS XML to JSON for frontend consumption.

Configuration

  • Convert XML config to JSON: Migrate old XML configs (log4j, Spring XML, Maven) to JSON when tools support it.
  • Convert JSON config to XML: For tools that only accept XML.
  • Archive format: Keep configs in one format, convert for other tools.

Debugging

  • Inspect XML responses: XML is verbose. Convert to JSON for easier reading.
  • SOAP message inspection: SOAP XML is dense. JSON view is more scannable.
  • Format bridging: Different teams use different formats — convert for review.

JSON to XML Converter — examples

Simple object

JSON to XML.

Input
{
  "user": {
    "name": "Alice",
    "age": 30
  }
}
Output
<user>
  <name>Alice</name>
  <age>30</age>
</user>

With attributes

@-prefix becomes attribute.

Input
{
  "book": {
    "@id": "123",
    "@lang": "en",
    "title": "XML Guide"
  }
}
Output
<book id="123" lang="en">
  <title>XML Guide</title>
</book>

Array

Repeated elements.

Input
{
  "users": {
    "user": [
      {"name": "Alice"},
      {"name": "Bob"}
    ]
  }
}
Output
<users>
  <user>
    <name>Alice</name>
  </user>
  <user>
    <name>Bob</name>
  </user>
</users>

XML to JSON

Reverse direction.

Input
<user id="1" role="admin">Alice</user>
Output
{
  "user": {
    "@id": "1",
    "@role": "admin",
    "#text": "Alice"
  }
}

SOAP envelope

Complex SOAP structure.

Input
{
  "soap:Envelope": {
    "@xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/",
    "soap:Body": {
      "getUser": {
        "id": "42"
      }
    }
  }
}
Output
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getUser>
      <id>42</id>
    </getUser>
  </soap:Body>
</soap:Envelope>

Namespaces

XML with declared namespaces.

Input
<root xmlns:ns="http://example.com">
  <ns:element>value</ns:element>
</root>
Output
{
  "root": {
    "@xmlns:ns": "http://example.com",
    "ns:element": "value"
  }
}

Technical details

JSON ↔ XML conversion conventions:

Simple object to XML:

JSON:
``json
{
"user": {
"name": "Alice",
"age": 30
}
}
``

XML:
``xml
<user>
<name>Alice</name>
<age>30</age>
</user>
``

Attributes (via @ prefix convention):

JSON:
``json
{
"book": {
"@id": "123",
"@lang": "en",
"title": "XML Guide"
}
}
``

XML:
``xml
<book id="123" lang="en">
<title>XML Guide</title>
</book>
``

Arrays:

JSON:
``json
{
"users": {
"user": [
{"name": "Alice"},
{"name": "Bob"}
]
}
}
``

XML:
``xml
<users>
<user>
<name>Alice</name>
</user>
<user>
<name>Bob</name>
</user>
</users>
``

Text content alongside attributes:

JSON:
``json
{
"message": {
"@priority": "high",
"#text": "This is important"
}
}
``

XML:
``xml
<message priority="high">This is important</message>
``

Namespaces:

JSON:
``json
{
"root": {
"@xmlns:ns": "http://example.com",
"ns:element": "value"
}
}
``

XML:
``xml
<root xmlns:ns="http://example.com">
<ns:element>value</ns:element>
</root>
``

CDATA sections:

Content with special characters (code, HTML) can be preserved in CDATA:

JSON (convention):
``json
{
"script": {
"#cdata": "if (x < 5) doSomething();"
}
}
``

XML:
``xml
<script><![CDATA[if (x < 5) doSomething();]]></script>
``

Reverse direction (XML → JSON):

Attributes become @-prefixed properties:

XML:
``xml
<user id="1" role="admin">Alice</user>
``

JSON:
``json
{
"user": {
"@id": "1",
"@role": "admin",
"#text": "Alice"
}
}
``

Single vs repeated elements:

XML:
``xml
<users>
<user>Alice</user>
</users>
``

JSON (single element — not array):
``json
{
"users": {
"user": "Alice"
}
}
``

But if multiple:

``xml
<users>
<user>Alice</user>
<user>Bob</user>
</users>
``

``json
{
"users": {
"user": ["Alice", "Bob"]
}
}
``

This context-sensitive behavior (is "user" a single or list?) is a common conversion gotcha. Solutions:

1. Always array: force user array even for 1 element. Predictable but ugly for single-element cases.
2. Based on XSD hint: if schema says users can repeat, always array.
3. Infer from data: current element single, future might be array. Consumer needs to handle both.

Type handling:

XML has no types — everything is a string. JSON has typed values. Conversion loses type info in XML direction (42 becomes "42" string) unless you use explicit typing (XSD or naming conventions).

Round-trip fidelity:

JSON → XML → JSON usually preserves structure. But:
- Original XML attribute order lost in JSON.
- Empty XML elements vs JSON null: conversion may differ.
- Mixed content (text + elements interleaved): hard to round-trip cleanly.

Common use cases:

- SOAP to REST migration: wrap SOAP calls, convert XML responses to JSON for frontend.
- Legacy system integration: modern app talks JSON, legacy system talks XML.
- Data format conversion: migrate data archives between systems.
- Import/export: user-facing applications may need to accept either format.

Common problems and solutions

XML attributes lose order

XML attribute order is not semantically significant but JSON objects have no guaranteed order. Round-trip may change order. Usually safe.

Single vs array element ambiguity

XML <user>Alice</user> could be one user or first of many. JSON distinguishes. Tool infers based on source data but may guess wrong. Use schema-aware tools for critical cases.

Mixed content

<p>Before <b>bold</b> after</p> has text + element + text. Hard to represent in JSON cleanly. Tool uses array or special #text handling. Check output.

Losing type info in XML direction

XML has no types — all values become strings. 42 becomes "42". Type recovered on XML to JSON using XSD or heuristics.

Large XML attributes

XML allows arbitrary attribute names with special chars. JSON keys are strings but some chars are unusual. Tool handles with quotes.

Conflicting element names

Two elements with different structures but same name. XML allows; JSON forces same type. May require array of mixed objects.

XML whitespace

XML has complex whitespace rules. JSON is simpler. Conversion may normalize whitespace differently. Usually OK but check for visual differences.

Processing instructions and DTD

XML has <?xml-stylesheet ... ?> and DTD declarations. JSON has no equivalent. These are lost on conversion.

JSON to XML Converter — comparisons and alternatives

JSON to XML vs JSON Formatter: Different tools. Formatter just formats JSON. This converts JSON to different format entirely.

JSON vs XML: JSON is compact and matches JavaScript objects. XML is verbose but richer (attributes, namespaces, comments). Modern APIs use JSON; legacy and some industries use XML.

JSON to XML vs JSON to YAML: Both conversions between structured formats. XML is more verbose and strict. YAML is readable. Use XML for SOAP/legacy, YAML for configs.

Conversion libraries: Node.js: xml2js, fast-xml-parser. Python: xmltodict, lxml. Java: Jackson XmlMapper. This tool for browser-based ad-hoc.

Single vs repeated element gotcha: Most complex aspect of XML to JSON. Solutions: force arrays always, force based on XSD, or accept ambiguity. Context matters.

XML to JSON vs XPath: For querying XML, XPath is a query language. For converting entire structure, XML to JSON. Different use cases — often combined (convert structure, then query converted JSON).

Frequently asked questions about the JSON to XML Converter

Why convert between JSON and XML?

Modern REST APIs use JSON. Legacy systems (SOAP, enterprise XML, industry formats) use XML. Converting bridges old and new: modern apps consuming legacy XML APIs, migration projects, format-agnostic tools that accept both.

How are XML attributes represented in JSON?

Common convention: @-prefix. <user id="1"> becomes {"user": {"@id": "1"}}. Some libraries use _attributes nested object instead. Pick the convention your consumer expects.

How is XML text content with attributes handled?

Use #text property for text content alongside attributes. <msg priority="high">Important</msg> becomes {"msg": {"@priority": "high", "#text": "Important"}}.

Is my data safe?

Yes. Conversion in your browser. Data never uploads. Safe for SOAP payloads with credentials, enterprise data, sensitive XML.

What about single vs array for XML elements?

Tricky conversion issue. <users><user>Alice</user></users> — is user a single element or array of one? Without schema, cannot tell. Options: (1) Always use array. (2) Infer from data. (3) Specify in schema/config.

Does it preserve namespaces?

Yes. XML namespace declarations (xmlns:ns=) and prefixed elements (ns:element) preserved in both directions.

How does it handle CDATA?

CDATA sections preserved as special #cdata properties. Converting back to XML wraps in CDATA. For raw output without CDATA wrapping, escape characters instead.

What about mixed content?

Mixed content like <p>Before <b>bold</b> after</p> is awkward in JSON. Tool uses arrays with text and element mixing. May require manual restructuring.

Will type information be preserved?

JSON to XML: types lost (XML is all strings). XML to JSON: types inferred from content (42 becomes number 42 if detected). For preserved types, use XSD schema hints.

What about HTML?

HTML is XML-like but not strict XML (optional closing tags, different entity rules). Use dedicated HTML parsers for HTML. XML parsers fail on real-world HTML.

Additional resources

Advertisement

Related tools

All Converters

Learn more

Explore more tools

200+ free tools that run in your browser.

Browse all tools →