EUComply
  • EN
Contents
  1. The Transmute CLI (free, zero dependencies)
  2. Python equivalent
  3. Things that bite people
  4. Pipelines like this — without writing a script

How to Convert JSON to XML

1 min read

Some enterprise endpoints, older SOAP services and Java tooling still only accept XML. When your data lives in JSON, here's the shortest path across.

The Transmute CLI (free, zero dependencies)

Given users.json:

[
  { "name": "Alice", "age": 32 },
  { "name": "Bob",   "age": 20 }
]
$ npx github:mahope/transmute users.json --output xml --pipe '[{"op":"head","n":10}]'
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <item>
    <name>Alice</name>
    <age>32</age>
  </item>
  ...
</data>

Because parsing, transforming and serializing are separate steps, you can reshape before emitting XML:

$ npx github:mahope/transmute users.json     --pipe '[{"op":"filter","expr":"item.age >= 21"},{"op":"sort","by":"name"}]'     --output xml

Python equivalent

import json
from dicttoxml import dicttoxml

data = json.load(open("users.json"))
print(dicttoxml(data).decode())

pip install dicttoxml. Works, but pulls in more of your dependency tree than most one-off jobs justify.

Things that bite people

  • Arrays of objects map naturally; a single bare object needs wrapping first (Transmute does this automatically).
  • Special characters in values must be escaped (&, <). A serializer handles this; string concatenation does not.
  • Nulls: decide whether they become empty elements or disappear — be consistent.

Pipelines like this — without writing a script

The Transmute CLI is free (npx github:mahope/transmute). The desktop app adds an interactive pipeline builder, live preview and batch processing — one-time $19, no subscription.

Try the live demo →   See pricing