I Built a CSV to JSON Converter in 30 Lines of Python - It Replaced My $50 SaaS
Source: Dev.to
Introduction
Every data analyst, engineer, and researcher faces the same problem:
- You have data in CSV.
- You need it in JSON.
So you:
- Open an online converter (Cloudinary, Zamzar, CloudConvert)
- Upload the file (privacy concern: uploading data to a stranger’s server)
- Wait for processing (slow)
- Download the JSON
- Repeat 20 times a month
If you need to convert more than 100 rows you hit the free‑tier limit and have to pay $50‑$100 / month for a subscription.
Last month I did the math: I was converting CSVs 50+ times monthly.
$50 / mo SaaS = $600 / year for something that should take 30 seconds.
So I built a CSV‑to‑JSON Converter CLI in Python – 30 lines, zero dependencies, completely free. Since then I’ve never paid another subscription.
The Problem: CSV → JSON Is Simple (But Expensive)
CSV‑to‑JSON conversion is trivial programmatically, but online tools charge because they have to:
- Host servers – costs money, passed to users
- Rate limit – throttle free users to force upgrades
- Data privacy – you upload your files to their servers (sketchy)
- File‑size limits – free tier: 2 MB. Want to convert 50 MB? Pay up.
My usage vs. SaaS tools
| Tool | Cost | File limit (per month) | Speed |
|---|---|---|---|
| Cloudinary | $50 / mo | 100 MB / mo | Slow |
| Zamzar | $50 / mo | 250 MB / mo | Slow |
| CloudConvert | $48 / mo | 400 MB / mo | Slow |
| My Python script | $0 | Unlimited | Instant |
I built the Python version and never looked back.
The Solution: 30 Lines of Python
#!/usr/bin/env python3
"""CSV to JSON Converter – No dependencies, instant conversion, unlimited files"""
import csv
import json
import argparse
from pathlib import Path
def csv_to_json(csv_file, json_file=None, key_field=None, pretty=True):
"""Convert CSV to JSON."""
# Read CSV
with open(csv_file, 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
data = list(reader)
# If key_field specified, convert to dict
if key_field:
data = {row[key_field]: row for row in data}
# Write JSON
output_file = json_file or csv_file.replace('.csv', '.json')
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2 if pretty else None)
return output_file
def main():
parser = argparse.ArgumentParser(
description="Convert CSV to JSON instantly, no dependencies",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
csv-to-json data.csv
csv-to-json data.csv --output result.json
csv-to-json data.csv --key id
csv-to-json data.csv --minify
"""
)
parser.add_argument('csv_file', help='CSV file to convert')
parser.add_argument('--output', '-o', help='Output JSON file (default: data.json)')
parser.add_argument('--key', '-k', help='Use column as key (converts to dict)')
parser.add_argument('--minify', action='store_true', help='Minify JSON (no pretty print)')
args = parser.parse_args()
output = csv_to_json(args.csv_file, args.output, args.key, not args.minify)
print(f"✅ Converted {args.csv_file} → {output}")
if __name__ == "__main__":
main()
That’s it. No cloud servers, no rate limiting, no file‑size limits.
Real Examples
Example 1 – Basic CSV → JSON
Input CSV (users.csv):
id,name,email,role
1,Alice,alice@example.com,Engineer
2,Bob,bob@example.com,Manager
3,Charlie,charlie@example.com,Designer
Command
csv-to-json users.csv
Output JSON
[
{
"id": "1",
"name": "Alice",
"email": "alice@example.com",
"role": "Engineer"
},
{
"id": "2",
"name": "Bob",
"email": "bob@example.com",
"role": "Manager"
},
{
"id": "3",
"name": "Charlie",
"email": "charlie@example.com",
"role": "Designer"
}
]
Example 2 – Use a Column as the Key
Command
csv-to-json users.csv --key id
Output JSON
{
"1": {
"name": "Alice",
"email": "alice@example.com",
"role": "Engineer"
},
"2": {
"name": "Bob",
"email": "bob@example.com",
"role": "Manager"
},
"3": {
"name": "Charlie",
"email": "charlie@example.com",
"role": "Designer"
}
}
Much easier to look up by ID.
Example 3 – Minified (No Pretty Print)
Command
csv-to-json data.csv --minify
Output (single line, good for APIs or databases)
[{"id":"1","name":"Alice","email":"alice@example.com","role":"Engineer"},{"id":"2","name":"Bob","email":"bob@example.com","role":"Manager"},{"id":"3","name":"Charlie","email":"charlie@example.com","role":"Designer"}]
Real‑World Use Cases
- 📊 Data analysts – Convert CSV exports to JSON for APIs.
- 🏢 Enterprise – Bulk‑convert legacy CSV data to JSON.
- 🤖 Automation – Pipe CSV through the script in CI/CD pipelines.
- 📱 Mobile apps – Convert CSV to JSON for local mobile databases.
- 🔗 API testing – Turn test‑data CSVs into JSON fixtures.
- 📈 BI tools – Feed CSV reports into JSON‑based dashboards.
Installation
git clone https://github.com/godlmane/csv-to-json-cli.git
cd csv-to-json-cli
python csv_to_json.py --help
Or simply copy the single Python file into any project – no setup required.
Benchmarks: My Script vs. SaaS
| Task | My Script | CloudConvert | Zamzar |
|---|---|---|---|
| Small file (1 KB) | Find a problem you pay for → Realize it’s simple → Build it in Python → Save money and time forever. |
Get It Now
👉 GitHub: csv-to-json-cli
Free. Open source. MIT licensed. Use forever.
The Ask
If the CSV‑to‑JSON converter saved you time or money, consider:
- ☕ Buy me a coffee – Helps me build more tools like this
- ⭐ Star the repo – Increases visibility for other data analysts
- 💬 Comment – What’s your biggest CSV/JSON pain point? I’ll build features based on real demand
Stop paying $50/month for 30 seconds of work. Use this tool. It’s free.
P.S. I’ve built 13 of these “replace your SaaS” tools. Each saves $100‑500/year in subscriptions. Combined: $2,000‑5,000/year saved. If that interests you, follow for the next tool.