Skip to content

Tiny CSV β†’ JSON Lines converter in ~1KB of Python. Zero dependencies. Golf-friendly πŸš€

License

Notifications You must be signed in to change notification settings

ozgunlu/nano-csv2json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

nano-csv2json

PyPI License Size CI

Tiny CSV β†’ JSON Lines converter β€” ~1 KB, zero deps. Single-file, CLI included. Auto-sniffs delimiter; headers optional. Perfect for code-golf, minimal containers, or just for fun.


✨ Features

  • βœ… CSV β†’ JSONL (one JSON per line)
  • βœ… Auto-detect delimiter (,, ;, \t, …)
  • βœ… Uses header row if present; --no-header β†’ keys: c1,c2,...
  • βœ… Zero dependencies, single tiny file

πŸš€ Usage

# Local (from repo)
python app_min.py data.csv
python app_min.py --no-header data_nohdr.csv

After installing:

# CLI
pip install nano-csv2json
nano-csv2json data.csv > out.jsonl
type data.csv | nano-csv2json         # Windows
cat data.csv | nano-csv2json          # Linux/macOS

Output is JSON Lines (newline-separated JSON objects).


πŸ€“ Why so small?

  • Uses only the stdlib: csv, json, io β€” no pandas.
  • Auto-detects delimiter with csv.Sniffer() (comma/semicolon/tab…).
  • Streams to JSON Lines (one JSON per line) β€” no in-memory data frames.
  • Header row β†’ csv.DictReader; --no-header β†’ c1,c2,... keys via csv.reader.
  • Single tiny file + tiny CLI: perfect for scripts, containers, CI.

πŸŽ‰ Fun Ideas

  • Pretty-print JSONL
nano-csv2json data.csv | python -m json.tool
  • Filter with jq
nano-csv2json data.csv | jq -r 'select(.status=="ok")'
  • STDIN piping
curl -s https://example.com/data.csv | nano-csv2json > out.jsonl
# Windows
Invoke-WebRequest https://example.com/data.csv -UseBasicParsing | nano-csv2json > out.jsonl
  • Semicolon/TSV auto-sniff
nano-csv2json data_semicolon.csv > out.jsonl
nano-csv2json data.tsv > out.jsonl
  • No header β†’ synthetic keys
nano-csv2json --no-header raw.csv | head -1
# {"c1":"val1","c2":"val2",...}
  • Compress on the fly
nano-csv2json data.csv | gzip > out.jsonl.gz
  • First N records
nano-csv2json data.csv | head -100 > sample.jsonl

Tip: Need a single JSON array? Collect lines with jq: nano-csv2json data.csv | jq -s '.' > array.json


πŸ“œ License

MIT Β© 2025

About

Tiny CSV β†’ JSON Lines converter in ~1KB of Python. Zero dependencies. Golf-friendly πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages