Skip to content

XML to JSON converter

XML to JSON runs through our table engine, mapping elements, attributes, text, and repeated children into JSON conventions.

  • Converted with Table engine · nothing stored
  • Free: 5 conversions a day · 5 MB each
  • Higher limits →

From real runs

What you get — and what changes

  • Elements Kept

    Simple child elements become nested JSON object properties using the XML element names.

  • Repeated children Changed

    Repeated child elements become arrays, so multiple item nodes stay grouped under one key.

  • Attributes Changed

    Attributes are moved to @attr keys to avoid collisions with element text and children.

  • Text plus attributes Changed

    When an element has both attributes and text, the text is stored under #text.

  • Namespaces Kept

    Namespace prefixes are kept in names such as atom:entry; the converter does not rewrite them into namespace URI objects.

  • Mixed content Lost

    Mixed text and inline child order is lossy because JSON objects do not preserve the exact XML content stream.

  • Comments and processing instructions Lost

    XML comments, declarations, and processing instructions are not included in the JSON data output.

Sample conversions

Catalog with attributes

Input
<catalog><product id="p-100"><name>Hoodie</name><variant sku="H-S">Small</variant><variant sku="H-M">Medium</variant></product></catalog>
Output
{"catalog":{"product":{"@id":"p-100","name":"Hoodie","variant":[{"@sku":"H-S","#text":"Small"},{"@sku":"H-M","#text":"Medium"}]}}}

Namespaced feed

Input
<atom:feed><atom:entry><atom:title>Launch</atom:title></atom:entry></atom:feed>
Output
{"atom:feed":{"atom:entry":{"atom:title":"Launch"}}}; prefixes remain part of the JSON keys.

Mixed content warning

Input
<p>Hello <strong>world</strong>, today.</p>
Output
JSON keeps the p and strong data but loses exact inline text order; use HTML or XML when prose markup fidelity matters.

A real XML → JSON run

We converted our XML sample (733 B) with Table engine on 2026-09-11. It took 1 ms and produced a 558 B JSON file, 24% smaller than the input. The engine raised 1 warning, listed below.

Input · sample.xml · 733 B

25 elements, root <rows>, XML declaration present

Elements
25
Root element
rows
XML declaration
yes

Output · sample.json · 558 B

Array of 4 objects; keys: company, stage, arr, owner, close_date

Records
4
Keys
company, stage, arr, owner, close_date
  • XML rows were detected with a heuristic; pass rowPath for deterministic parsing.

First lines of the output

json
[
  {
    "company": "Northwind Traders",
    "stage": "Proposal",
    "arr": 48000,
    "owner": "R. Ayers",
    "close_date": "2026-10-14"
  },
  {
    "company": "Contoso Ltd",
    "stage": "Negotiation",
    "arr": 120000,
    "owner": "P. Ng",
    "close_date": "2026-09-30"
  },
  {
    "company": "Fabrikam",
    "stage": "Qualified",
…

Options and when to change them

attributePrefix
Keep @ for common XML-to-JSON conventions or change it if your data already uses @ keys.
textKey
Use #text for compatibility with many parsers, or set another key if your downstream API requires it.
rowPath
Set a repeated element path when you want tabular records extracted from a large XML document.

Do it yourself

xq

bash
xq . in.xml > out.json

xq uses its own XML mapping conventions; compare attribute and text keys before depending on exact names.

Python xmltodict

bash
python - <<'PY'
import json
import xmltodict
with open("in.xml", encoding="utf-8") as fh:
    doc = xmltodict.parse(fh.read())
with open("out.json", "w", encoding="utf-8") as fh:
    json.dump(doc, fh, indent=2, ensure_ascii=False)
PY

Install xmltodict first; mixed content still requires hand review.

XML to JSON by API or MCP

The HTTP API and the MCP server run the exact engine this page uses (Table engine); the response carries the same warnings the web converter shows. Check support first with GET /api/v1/pairs?from=xml&to=json.

curl
curl -X POST https://filetypeconverters.com/api/v1/convert \
  -H "Authorization: Bearer $FTC_API_KEY" \
  -F "file=@input.xml" -F "from=xml" -F "to=json" \
  -F 'options={"encoding":"utf-8"}' \
  --output output.json

Options this engine accepts for XML → JSON

KeyApplies toTypeDefault
encodingReading XMLutf-8 · latin1utf-8
flattenSeparatorReading XMLstring.
arrayModeReading XMLjson · explodejson
rowPathReading XMLstring
delimiterWriting JSONstring,
newlineWriting JSON ·
sheetNameWriting JSONstring
dialectWriting JSONpostgres · mysql · sqlitepostgres
tableNameWriting JSONstringdata
createTableWriting JSONbooleantrue
API reference

When this is the wrong conversion

  • Do not convert XML to JSON when exact mixed-content order, comments, or processing instructions are legally significant.
  • If namespace URI resolution matters, use an XML-aware parser instead of prefix-only JSON keys.
  • For large repetitive XML that feeds a spreadsheet, XML to CSV may be more convenient than generic JSON.

XML to JSON questions

How are XML attributes represented in JSON?

Attributes become keys prefixed with @, such as @id or @sku, so they do not collide with child element names.

What happens to repeated XML child elements?

Repeated child elements become arrays. A list of multiple <item> nodes becomes an item array in JSON.

Are XML namespaces removed?

No. Prefixes are kept in key names, such as atom:title. The converter does not expand them into namespace URI metadata.