Skip to main content

JSON to XML and XML to JSON Converter

Switch quickly between JSON and XML structures and get formatted output ready to copy or reuse in your project.

  • Clipboard
  • Export
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Was this tool useful?

How does this tool work?

Convert a JSON structure to XML or simple element-based XML to JSON. These formats carry different information, so this tool uses an explicit limited convention rather than promising a universal round trip. Processing stays in your browser. Use it for a small data exchange or to inspect a service response, then check the receiving contract. XML with attributes or mixed prose needs a richer conversion model.

Direction comes from the trimmed input: { or [ selects JSON to XML; other input goes to XML parsing. JSON to XML adds a root element named root. Properties become elements, and arrays contain item elements. Keys must be supported simple XML names; spaces, colons and names starting with xml are rejected. Text characters are escaped to produce valid XML.

XML to JSON retains the root name. Repeated same-named siblings become an array; a single element remains a scalar or object. Leaves are strings: <n>2</n> becomes "2", not the number 2. Empty leaves become empty strings. Attributes, comments, processing instructions and unrepresentable mixed content are rejected instead of silently dropped. DOCTYPE is also rejected.

No business schema is inferred. Order across groups of differently named elements may be lost in JSON, and XML cannot distinguish a single-item list from one standalone element. Text versions of null, numbers and booleans do not regain their JSON types automatically. Conversion depth is limited; JSON numbers use the browser’s numeric precision. Use strings for long identifiers if your contract allows it.

How to use this tool

  1. Paste the source structure

    Provide a JSON object or array, or a complete XML document. Direction is automatic without a separate direction control.

  2. Review the conversion

    Run it and check types, root and arrays. An error message is not a usable partial conversion.

  3. Export the appropriate format

    Copy or download .xml or .json. Errors are presented as text; retain the original to check structural distinctions that do not survive conversion.

Use cases

Adapt a simple exchange

Turn a small object into XML elements for an integration example. The receiver must accept root or you must adapt it deliberately.

Read an XML list

Inspect repeated siblings as a JSON array. Also test a single element, whose output shape differs.

Identify an incompatibility

An attributes or mixed-content rejection means this model cannot represent part of your document. Keep the source and choose a richer mapping.

Examples

An object under root

The engine wraps the object in root and turns name into an element. Converting back does not automatically remove that added root.

Input

{"name":"Ada"}

Result

<root><name>Ada</name></root>

Group repeated siblings

The two item elements become an array of strings under root. Their text is not interpreted as numbers, booleans or JSON documents.

Input

<root><item>A</item><item>B</item></root>

Result

{
  "root": {
    "item": [
      "A",
      "B"
    ]
  }
}

Tips and best practices

  • Do not replace signed documents with converted versions: representations and signatures are not equivalent.
  • Test zero, one and multiple elements. A contract that always expects arrays needs explicit normalization of the special cases.
  • Do not turn a JSON key into an improvised namespace prefix; the engine rejects colons rather than generating undeclared prefixes.

Sources and references

Frequently asked questions

Why are XML attributes rejected?

This convention defines no attribute representation. Ignoring them would lose data; rejection lets you choose a mapping suited to your format.

Why do XML numbers become strings?

Simple XML contains text without JSON types. The tool does not guess whether 01 is a code, a number or text to preserve.

Can I convert primitive JSON?

The interface detects objects and arrays using { or [. A standalone string, number or null does not select JSON to XML.

Does a round trip restore the original?

No. Added roots, textual types, sibling grouping and cardinality can alter structure. Compare output with the intended contract, not just field names.

Related tools

Tools similar or complementary to this one.

Similar tools

Format, minify, and validate an XML document directly in your browser.

DevelopmentUse this tool

Format, minify, and validate JSON to make it easier to read or more compact.

DevelopmentFeaturedUse this tool