XML to JSON

Convert XML into JSON instantly

Paste XML on the left and get JSON on the right — all in your browser

Last updated: January 28, 2026
Frank Zhao - Creator
CreatorFrank Zhao
{
  "a": {
    "_attributes": {
      "x": "1.234",
      "y": "It's"
    }
  }
}

Introduction / overview

The XML to JSON converter turns XML markup into a JSON representation you can copy into logs, config files, API payloads, or quick prototypes. Everything runs locally in your browser, so you can safely convert data without sending it to a server.

Quick mental model: XML is a tree. JSON is a tree. The converter maps one tree shape into the other.

Who typically uses this?

  • Developers migrating legacy XML APIs to modern JSON-based services.
  • Analysts converting XML exports into JSON for scripts and tooling.
  • Students learning how XML attributes and text nodes translate to structured data.

Reliability note: This converter uses the same underlying transformation approach as the open-source it-tools implementation.

Related converters you may also want:

How to Use / Quick Start

If your XML is valid, the JSON output updates automatically. If it's invalid, you'll see a clear error state and the output will stay empty.

1

Paste your XML

Drop it into the left box. Self-closing tags and attributes are supported.

2

Check the JSON structure

Attributes typically appear under a dedicated key (for example, _attributes), and text nodes may appear under a text key depending on the XML.

3

Copy or share

Copy JSON

Use the copy button on the output panel.

Share link

Optionally include your XML in the link.

Interpreting the result (quick sanity checks)

  • If you see _attributes, that's your XML attributes.
  • Repeated tags may become arrays, depending on the source XML shape.
  • Empty output usually means invalid XML or an empty input.

How to Use / Step-by-step Examples

Below are two small examples that mirror how the converter represents attributes and how sharing works.

Example 1: attributes on a self-closing tag

Paste this XML:<a x="1.234" y="It's"/>

The converter outputs JSON where attributes are grouped. You don't need to “calculate” anything — just remember attributes are data too.

A quick numeric sanity check

If you plan to share your input via URL, keep it under the built-in limit.

1200<60001200 < 6000

Here 12001200 is a sample input length (characters) and 60006000 is the maximum we include in a share link.

Example 2: estimating share-friendly size

If your XML is mostly ASCII, a quick estimate is that one character is roughly one byte. That gives you an intuitive feel for the share limit.

6000 chars6000\ \text{chars}\approx6000 bytes6000\ \text{bytes}\approx6 KB6\ \text{KB}

This is a rough estimate, but it's handy when you're copying data from logs.

Real-World Examples / Use Cases

API migration checks

Background: you receive XML responses but your new service expects JSON.

Input: a sample XML payload. Output: a JSON structure you can map to DTOs.

Tip: once you have JSON, validate/reshape it further with YAML to JSON or your own scripts.

Config conversion

Background: you have XML-based config and want a JSON snapshot for documentation.

Input: an XML config section. Output: JSON you can paste into docs or issues.

22 spaces per indent\text{ spaces per indent}\Rightarrowreadable diffs\text{readable diffs}

Pretty output makes code reviews calmer.

Redacting sensitive fields

Background: XML exports can contain secrets. Convert to JSON, then search-and-replace specific keys.

Input: an XML export. Output: JSON that is easier to scan and sanitize.

Always double-check you didn't share credentials.

Debugging and logging

Background: your logs store JSON more cleanly than XML.

Input: a failing XML sample. Output: JSON you can paste into tickets.

Next step: if your JSON needs to become YAML for config files, use JSON to YAML converter.

Common Scenarios / When to Use

You have XML snippets in docs

Convert them to JSON examples for easier copy/paste in code.

You need JSON for quick tooling

Many CLIs and APIs accept JSON natively.

You want a safer review format

JSON is often easier to diff and review than raw XML.

You need to paste into a bug report

JSON tends to be more compact and familiar to reviewers.

You want to share a reproducible sample

Use the Share dialog to generate a link, optionally including input.

When it may not fit

If your XML uses complex mixed content, mapping can be surprising.

When it might not be ideal

  • XML with heavy mixed content (text + nested tags interleaved) may not convert cleanly.
  • If you need a strict JSON schema, you'll still want a custom mapping step.

Tips & Best Practices

Keep the XML minimal when debugging

Start with the smallest XML that reproduces your issue. Once the JSON shape makes sense, add fields back.

Avoid accidental leaks

  • Before sharing a link, remove tokens, emails, addresses, and IDs.
  • Consider sharing a reduced sample instead of full production data.

Normalize after converting

If you need the output in another format, convert the JSON further:

Calculation Method / Formula Explanation

Conceptually, the converter parses XML into an internal object tree, then serializes that tree as JSON. The formatting uses a fixed indentation for readability.

High-level transformation

X=parse(XML)X=\operatorname{parse}(\mathrm{XML}),,J=stringify(X, 2)J=\operatorname{stringify}(X,\ 2)

Here XX is the parsed tree and JJ is the formatted JSON string (pretty-printed with 22 spaces).

Variables

  • XML\mathrm{XML}: your input string.
  • XX: the parsed representation (object tree).
  • JJ: the output JSON text.

Related Concepts / Background Info

Why attributes look different

XML distinguishes between attributes and nested elements, while JSON does not. Converters typically preserve that distinction using a dedicated key (like _attributes) so that you don't lose information.

Arrays vs objects

XML doesn't have a built-in array type. Repeated sibling tags (like multiple <item>) are often treated as arrays in JSON. If your downstream code expects arrays, confirm the shape using a small sample first.

Frequently Asked Questions (FAQs)

Why do I see an _attributes key?

Because JSON doesn't have a native concept of XML attributes. Grouping attributes under a dedicated key keeps the conversion lossless.

My repeated tags didn't become an array. Is that wrong?

Not necessarily. Some XML structures represent lists using wrappers or explicit item tags. If you need a specific array shape, you may need an extra normalization step after conversion.

Does the converter send my XML to a server?

No. Conversion happens locally in your browser.

Why is the output pretty-printed?

Pretty output is easier to read and debug. This tool formats JSON with 22 spaces so it's clean to copy.

What if my XML is invalid?

The input panel will show an error state and the output will remain empty until the XML becomes valid.

Limitations / Disclaimers

Converting XML to JSON is not always one-to-one. Mixed content, namespaces, and custom conventions can produce surprising shapes. Always validate the result against your downstream requirements.

Not professional advice

This tool is a convenience converter. For critical systems, implement a dedicated schema-driven mapper and add tests.

External References / Sources

XML to JSON | CalculatorVast