Every major operating system can convert CSV to JSON natively — Mac and Linux with Python, Windows with PowerShell. Here are the exact commands for each platform, plus the cross-platform browser option that skips the terminal entirely.
macOS ships with Python 3. Most Linux distributions (Ubuntu, Fedora, Debian, Arch) include it too. Open your terminal and run:
python3 -c "import csv,json,sys; print(json.dumps(list(csv.DictReader(open(sys.argv[1], encoding='utf-8-sig'))), indent=2))" data.csv
This prints formatted JSON directly to your terminal. To save it as a file:
python3 -c "import csv,json,sys; print(json.dumps(list(csv.DictReader(open(sys.argv[1], encoding='utf-8-sig'))), indent=2))" data.csv > output.json
What is happening in that one-liner:
PowerShell ships with every Windows 10 and 11 installation. No Python, no npm, no downloads needed:
Import-Csv data.csv | ConvertTo-Json | Out-File output.json
That is the entire command. PowerShell reads the CSV, converts each row to a PowerShell object, serializes to JSON, and writes the file.
For large files, add depth control and encoding:
Import-Csv data.csv -Encoding UTF8 | ConvertTo-Json -Depth 10 | Out-File output.json -Encoding UTF8
PowerShell gotcha: By default, ConvertTo-Json has a depth limit of 2. If your data is simple (flat CSV), this does not matter. If you are processing complex data, set -Depth 10 to avoid truncation.
If you do not want to open a terminal at all:
Works on Mac, Windows, Linux, ChromeOS, tablets, and phones. No Python version issues, no PATH configuration, no terminal familiarity required.
| Criteria | Mac/Linux Python | Windows PowerShell | Browser Tool |
|---|---|---|---|
| Pre-installed? | ✓ Yes (Mac + most Linux) | ✓ Yes (Win 10/11) | ✓ Just needs a browser |
| Speed for small files | ✓ Instant | ✓ Instant | ✓ Instant |
| Speed for large files | ✓ Handles millions of rows | ~Slower on 100K+ rows | ~Slows at 50K+ rows |
| Encoding handling | ✓ utf-8-sig for BOM | ✓ -Encoding UTF8 | ✓ Automatic |
| Scriptable / automatable | ✓ Cron, bash scripts | ✓ Task Scheduler | ✗ Manual process |
| Learning curve | ~Need terminal basics | ~Need PowerShell basics | ✓ None — paste and copy |
| Custom delimiters | ✓ delimiter parameter | ✓ -Delimiter parameter | ✓ Dropdown or auto-detect |
| Data stays local | ✓ Yes | ✓ Yes | ✓ Yes (no upload) |
Mac/Linux — add to your shell profile:
# Add to ~/.bashrc or ~/.zshrc
csv2json() { python3 -c "import csv,json,sys; print(json.dumps(list(csv.DictReader(open(sys.argv[1], encoding='utf-8-sig'))), indent=2))" "$1"; }
Then convert any file with: csv2json data.csv > output.json
Windows — create a PowerShell function:
# Add to your PowerShell profile
function csv2json { param($f) Import-Csv $f -Encoding UTF8 | ConvertTo-Json -Depth 10 }
Then: csv2json data.csv | Out-File output.json
| Platform | Gotcha | Fix |
|---|---|---|
| Mac | python vs python3 — macOS may have Python 2 as default | Always use python3 explicitly |
| Ubuntu 24+ | Python may not be pre-installed on minimal installs | sudo apt install python3 |
| Windows | PowerShell execution policy may block scripts | Run Set-ExecutionPolicy RemoteSigned in admin terminal |
| Windows | ConvertTo-Json wraps single-row CSV in object, not array | Pipe through @() to force array: @(Import-Csv file) | ConvertTo-Json |
| All | CSV from Excel has invisible BOM bytes | Python: utf-8-sig encoding. PowerShell: -Encoding UTF8. |
| All | European CSV uses semicolons, not commas | Python: delimiter=";" — PowerShell: -Delimiter ";" |
Works on Mac, Windows, Linux — paste CSV, get JSON, no install needed.
Open CSV to JSON Converter