Developers constantly need to move data between formats. APIs return JSON. Analysts want Excel. DevOps configs are YAML. Legacy systems need XML. This guide covers every major data format conversion with working Python code and a free no-code option.
The five formats every developer needs
- JSON — default for APIs, JavaScript applications, NoSQL databases
- CSV — spreadsheets, database imports, data exchange
- YAML — configuration files, Kubernetes, Docker Compose, CI/CD
- XML — enterprise systems, SOAP APIs, RSS feeds, Office documents
- Excel (.xlsx) — business reporting, analyst workflows, data sharing
JSON to CSV
import json, csv
with open('data.json') as f:
data = json.load(f)
with open('output.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
print("JSON → CSV done")
CSV to JSON
import csv, json
with open('data.csv') as f:
rows = list(csv.DictReader(f))
with open('output.json', 'w') as f:
json.dump(rows, f, indent=2, ensure_ascii=False)
print(f"CSV → JSON: {len(rows)} records")
JSON to YAML
import json, yaml
with open('config.json') as f:
data = json.load(f)
with open('config.yaml', 'w') as f:
yaml.dump(data, f, allow_unicode=True,
default_flow_style=False, sort_keys=False)
print("JSON → YAML done")
YAML to JSON
import yaml, json
with open('config.yaml') as f:
data = yaml.safe_load(f)
with open('config.json', 'w') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
print("YAML → JSON done")
JSON to Excel
import pandas as pd
df = pd.read_json('data.json')
df.to_excel('output.xlsx', index=False, engine='openpyxl')
print(f"JSON → Excel: {df.shape[0]} rows, {df.shape[1]} columns")
Excel to CSV
import pandas as pd
df = pd.read_excel('data.xlsx', engine='openpyxl')
df.to_csv('output.csv', index=False)
print(f"Excel → CSV: {len(df)} rows")
XML to JSON
import xml.etree.ElementTree as ET
import json
def xml_to_dict(element):
result = {}
for child in element:
child_data = xml_to_dict(child)
if child.tag in result:
if not isinstance(result[child.tag], list):
result[child.tag] = [result[child.tag]]
result[child.tag].append(child_data)
else:
result[child.tag] = child_data
if element.text and element.text.strip():
return element.text.strip()
return result or element.text
tree = ET.parse('data.xml')
root = tree.getroot()
data = {root.tag: xml_to_dict(root)}
with open('output.json', 'w') as f:
json.dump(data, f, indent=2)
print("XML → JSON done")
💡 No-code option: All 20 format combinations (JSON, CSV, YAML, XML, Excel in any direction) are available in Sylvaera's free Data Format Converter. Paste or upload your data, select input and output formats, download instantly.
Choosing the right format
- Sharing with developers → JSON
- Sharing with analysts or business teams → Excel or CSV
- Configuration files → YAML (more readable) or JSON (more strict)
- Enterprise system integration → XML
- Database imports → CSV
- API payloads → JSON (minified)
Always validate data after conversion — especially when going from a typed format (Excel, JSON) to a less-typed one (CSV), and back again. Type information can be lost in the round trip.
Try Data Format Converter — Free
Convert between JSON, CSV, YAML, XML and Excel instantly. Paste or upload your data, select formats, download in one click. Zero AI cost — pure instant conversion.
Open Data Format Converter →