XML to JSON & JSON to XML

Paste XML or JSON in the left pane; direction is detected from the text. Convert, then copy from the output.

XML and JSON in enterprise and API design

XML models documents as a tree of elements with optional attributes, namespaces, and text nodes—well suited to contracts (SOAP, WSDL), syndication (RSS, Atom), crawlers (sitemap), and regulated payloads where schema validation (XSD) matters. JSON favors nested objects and arrays with a small scalar set; it dominates REST, OpenAPI, browser clients, and log or event pipelines.

Teams rarely choose one format forever. Integration buses, legacy ERP endpoints, and payment gateways often speak XML while mobile apps and BFF layers emit JSON. Structural conversion clarifies the same logical fields across formats; it does not replace schema design, namespace policy, or API versioning.

XML and JSON — background

Parallel tree structures

  1. JSON objects map to XML elements whose child content is mostly nested elements and text.
  2. JSON arrays often represent repeated sibling XML elements with the same tag name.
  3. JSON strings, numbers, booleans, and null correspond to text nodes and simple element values when typing is unambiguous.
  4. XML attributes have no native JSON slot; conventions use a sibling object (for example @name or $ for text with attributes).

What XML adds beyond JSON

  1. Attributes carry metadata on elements (ids, types, href) without extra nesting depth.
  2. Namespaces (xmlns) disambiguate tag names across vendors and standards bodies.
  3. Mixed content interleaves text and child elements—common in HTML-like and document-centric XML.
  4. Processing instructions, CDATA sections, and comments exist in the source but rarely round-trip into JSON.

Mapping and array semantics

  • One XML element with a given name may become an object or a one-item array depending on converter rules—know your consumer.
  • Attribute-heavy records (SOAP headers, sitemap url entries) need a stable attribute key naming scheme in JSON.
  • Text-only elements and empty elements differ in XML; JSON may collapse both to null or empty string.
  • Order of sibling elements can matter in XML documents; JSON object key order is not semantically significant in most APIs.

Where conversion stops

  • SOAP envelopes, WS-Security tokens, and digital signatures depend on exact XML infoset—not a generic JSON snapshot.
  • Default namespace prefixes and xsi:type hints may be lost unless you preserve xmlns in a sidecar schema.
  • Sitemap and RSS are valid XML for crawlers; JSON views help analytics but do not replace canonical XML URLs for search engines.

Where representation shifts matter

Legacy SOAP and ESB bridges

Inspect envelope and body fields as JSON for logging or unit tests while production traffic stays XML against the WSDL contract.

Feeds and crawler artifacts

Understand sitemap url/loc/priority/changefreq or RSS item structure as nested data before transforming in ETL or observability pipelines.

Frequently asked questions

How are XML attributes represented in JSON?
Converters typically attach attributes on a special key (often @attributeName) alongside element text, or merge them into the parent object. There is no single RFC—document the convention your stack expects before piping into JSON formatter or downstream validators.
Why do repeated XML elements become JSON arrays?
Multiple siblings with the same tag cannot be unique object keys, so parsers emit an array. A single sibling may stay an object; some tools always wrap repeats—check array normalization when comparing to OpenAPI list types.
What happens to XML namespaces?
Namespace URIs and prefixes are part of element identity in XML. JSON output often uses Clark notation {uri}localName or drops prefixes entirely. Cross-vendor merges fail silently if xmlns context is stripped.
How does SOAP relate to JSON views?
SOAP is an XML messaging pattern: Envelope, Header, Body, and Fault elements with typed payloads. JSON conversion helps read Body fields for debugging; it does not validate WS-I profiles, mustUnderstand headers, or replace an XML security layer.
How is sitemap.xml usually modeled in JSON?
A urlset contains repeated url elements; each url holds loc, optional lastmod, changefreq, and priority as child elements or attributes depending on the file. Arrays appear at the url level; attribute-style sitemaps need explicit attribute mapping.
Can JSON convert back to byte-identical XML?
Generally no. Insignificant whitespace, prefix choices, attribute order, and declaration lines differ. Treat JSON as a logical view; keep authoritative XML in source control for publishing.
How are text nodes and mixed content handled?
Element-only JSON may put character data in #text, $, or _value keys. Mixed content (text plus nested tags) loses hierarchy unless the converter preserves ordered node lists—rare in simple object mappings.
When should I use JSON formatter instead of this page?
When input is already strict JSON and you need pretty-print, minify, tree view, or JSON to YAML from a parsed tree, use JSON formatter & beautifier. This page focuses on XML and JSON structural views for integration and document-style payloads.