How to Convert XML to JSON

Legacy APIs, RSS feeds, SOAP responses, Maven and .NET config files โ€” XML is still everywhere, and almost every modern tool wants JSON. Here's how to convert it without hand-writing a parser.

Option 1: The Transmute CLI (free)

transmute parses XML records into JSON directly. Given this file (users.xml):

<data>
  <user><name>Alice</name><age>32</age></user>
  <user><name>Bob</name><age>25</age></user>
</data>

run:

$ transmute users.xml --format xml --pipe '[{"op":"head","n":10}]' --output json
[
  {
    "name": "Alice",
    "age": "32"
  },
  {
    "name": "Bob",
    "age": "25"
  }
]

You can chain operations in the same pass โ€” here filtering and reshaping before output:

$ transmute users.xml --format xml     --pipe '[{"op":"filter","expr":"Number(item.age) > 26"},{"op":"pick","fields":["name"]}]'     --output json
[
  {
    "name": "Alice"
  }
]

Option 2: Python

import xmltodict, json
with open("users.xml") as f:
    data = xmltodict.parse(f.read())
print(json.dumps(data, indent=2))

pip install xmltodict. Solid, but it's another dependency to pin, and attributes get @-prefixed keys you often have to clean up afterwards.

Option 3: In your browser

For a quick one-off without a terminal, the Transmute desktop app does the same conversion locally; nothing is uploaded.

Caveats worth knowing

  • XML has no types. Everything arrives as strings; use a pipeline step like Number(item.age) when you need real numbers.
  • Attributes vs elements. Converters differ on whether <user id="7"> becomes an "id" field. Check the output once before trusting it in bulk.
  • Mixed content (text plus child elements in one node) doesn't map cleanly to JSON in any tool.