Blog
Wild & Free Tools

Batch Convert Multiple XML Files to JSON: Free Options

Last updated: March 2026 5 min read
Quick Answer

Table of Contents

  1. Python: Batch Conversion Loop
  2. Shell: yq One-Liner
  3. Node.js: Batch with xml2js
  4. Small Batches: Browser Converter
  5. Frequently Asked Questions

Batch converting multiple XML files to JSON requires a scripted approach — no free browser tool handles multi-file batch processing. The fastest paths are a Python loop with xmltodict, a shell one-liner using yq, or a Node.js script with xml2js. This guide covers all three with copy-paste commands for immediate use.

Python: Batch XML to JSON with a Loop

Install xmltodict: pip install xmltodict

Convert all .xml files in a directory:

import xmltodict, json, os, glob

input_dir = './xml_files'

output_dir = './json_output'

os.makedirs(output_dir, exist_ok=True)

for xml_file in glob.glob(os.path.join(input_dir, '*.xml')):

with open(xml_file, 'r', encoding='utf-8') as f:

data = xmltodict.parse(f.read())

out_name = os.path.splitext(os.path.basename(xml_file))[0] + '.json'

with open(os.path.join(output_dir, out_name), 'w') as f:

json.dump(data, f, indent=2)

print(f'Converted: {xml_file}')

This script converts every .xml file in ./xml_files to a matching .json file in ./json_output. Adjust the paths as needed. For hundreds of files, add a progress counter.

Shell: yq One-Liner for Bulk XML to JSON

yq is a command-line tool for YAML/JSON/XML processing. Install it:

Mac: brew install yq

Linux: sudo snap install yq or download from the GitHub releases page

Windows: choco install yq or download the .exe from GitHub

Convert all XML files in a folder:

for f in *.xml; do yq -p xml -o json "$f" > "$(basename $f .xml).json"; done

This one-liner loops through every .xml file in the current directory and creates a corresponding .json file. Each .xml file becomes its own .json — data.xml becomes data.json.

yq is fast and handles namespaces, attributes, and nested elements correctly. For large-scale batch jobs (thousands of files), it's significantly faster than Python's xmltodict loop because it has less interpreter overhead per file.

Sell Custom Apparel — We Handle Printing & Free Shipping

Node.js: Batch Conversion with xml2js

Install xml2js: npm install xml2js

const xml2js = require('xml2js');

const fs = require('fs');

const path = require('path');

const inputDir = './xml_files';

const outputDir = './json_output';

if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);

const { parseStringPromise } = xml2js;

const files = fs.readdirSync(inputDir).filter(f => f.endsWith('.xml'));

Promise.all(files.map(async file => {

const xml = fs.readFileSync(path.join(inputDir, file), 'utf8');

const result = await parseStringPromise(xml, { explicitArray: false });

const outFile = file.replace('.xml', '.json');

fs.writeFileSync(path.join(outputDir, outFile), JSON.stringify(result, null, 2));

console.log('Done:', file);

}))

.then(() => console.log('All files converted.'));

Small Batches: Browser Converter One at a Time

For small batches (under 10 files), the browser converter is faster to use than setting up a script. Open the converter, paste or upload each XML file, copy or download the JSON. At 30–60 seconds per file, 10 files takes under 10 minutes.

The browser converter is also the right choice when: you're on a machine where you can't install Python or Node.js, the files are sensitive and you don't want to run a script on them, or you only need batch conversion once and don't want to maintain a script.

For regular batch jobs — daily XML feed processing, weekly data exports — script the Python or shell approach. For one-time conversions or small counts, the browser converter is faster to reach.

Single File? Use the Browser Converter

No script needed for one file. Paste XML, get JSON — free and instant.

Open Free XML to JSON Converter

Frequently Asked Questions

How many XML files can the Python script handle at once?

There's no hard limit. The script processes files sequentially — for thousands of files, add error handling around each parse call so a single malformed XML file doesn't stop the entire batch.

Can I convert XML files in subdirectories too?

Yes. Change glob.glob to use a recursive pattern: glob.glob(os.path.join(input_dir, "**/*.xml"), recursive=True). In yq's shell command, use find with the yq command for recursive processing.

What if some XML files are malformed?

xmltodict raises an exception for malformed XML. Wrap the parse call in try/except to log and skip invalid files rather than stopping the batch.

Does yq produce the same output format as xmltodict?

Very similar. Both follow the same conventions (attributes with @, repeated elements as arrays). Minor differences may exist in edge cases — test on a sample file from your batch first.

Tyler Mason
Tyler Mason File Format & Converter Specialist

Tyler spent six years in IT support where file format conversion was a daily challenge.

More articles by Tyler →
Launch Your Own Clothing Brand — No Inventory, No Risk