Xml2json
Convert XML to JSON with Python 3 and defusedxml or plain ElementTree
Install / Use
/learn @eliask/Xml2jsonREADME
xml2json
Convert XML to JSON with Python 3 and defusedxml or plain ElementTree
Usage
$ ./xml2json.py -h
usage: xml2json.py [-h] [--unsafe] [infile]
Convert an XML file to JSON.
positional arguments:
infile
optional arguments:
-h, --help show this help message and exit
--unsafe do not use defusedxml: only for known-safe XML!
Examples
# Normal usage for potentially unsafe XML files:
pip install defusedxml
./xml2json.py sample_input.xml > sample_output.json
# Without defusedxml
./xml2json.py --unsafe sample_input.xml > sample_output.json
# Also supports reading from stdin:
./xml2json.py < sample_input.xml > sample_output.json
Conversion logic
Each element gets converted into an object of the form: { tagName : {@text: optional, @children: optional, ...attributes} }
Input
<rootelem foo="bar">
some text
<child1>
<child2 attr1="baz" attr2="foo"/>
<child2 attr2="baz" attr3="foo"/>
</child1>
</rootelem>
Output
{
"rootelem": {
"foo": "bar",
"@text": "some text",
"@children": [
{
"child1": {
"@children": [
{
"child2": {
"attr1": "baz",
"attr2": "foo"
}
},
{
"child2": {
"attr2": "baz",
"attr3": "foo"
}
}
]
}
}
]
}
}
Related Skills
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
82.0kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
333.7kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
