This is a Python script that converts CSV files to JSON format. It supports automatic encoding detection, recursive directory traversal, and various customization options for the output JSON.
- Convert individual CSV files to JSON.
- Convert all CSV files in a directory (with optional recursion into subdirectories).
- Automatically detect the encoding of CSV files.
- Option to prevent overwriting existing JSON files.
- Option to output compact JSON (not pretty-printed).
- Verbose mode for detailed output.
- Python 3.x
chardet
library
pip install chardet
python .\csv-to-json-converter.py -h
usage: csv-to-json-converter.py [-h] [-o OUTPUT] [-v] [-r] [--no-overwrite] [-e ENCODING] [--compact] path
Convert CSV files to JSON
positional arguments: path File or directory path
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output directory for JSON files
-v, --verbose Enable verbose output
-r, --recursive Recursively search for CSV files in subdirectories
--no-overwrite Do not overwrite existing JSON files
-e ENCODING, --encoding ENCODING
Specify input CSV file encoding (default: auto-detect)
--compact Output compact JSON (not pretty-printed)
python csv-to-json-converter.py sample.csv
or
python csv-to-json-converter.py path/to/file.csv -o path/to/output
python csv-to-json-converter.py path/to/directory -o path/to/output
python csv-to-json-converter.py path/to/directory -o path/to/output -r
python csv-to-json-converter.py path/to/file.csv -o path/to/output -e utf-8 --compact
python csv-to-json-converter.py path/to/file.csv -o path/to/output -e utf-8 --compact
sample.csv
sample.json
This project is licensed under the MIT License. See the LICENSE file for details.
Created by dinoherlambang