A versatile Python utility that converts various file formats (Excel, CSV, TSV, etc.) to JSON.
- Automatic file type detection based on extension or content
- Support for multiple file formats:
- Excel (.xlsx, .xls, .xlsm, .xlsb, .odf, .ods, .odt)
- CSV (.csv)
- TSV (.tsv)
- JSON (.json)
- Text (.txt, .text)
- Multiple sheet support for Excel files
- Smart handling of merged cells in Excel (values from merged cells are properly propagated)
- Command-line interface
- Configurable output path
file2json/
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── pyproject.toml
├── file2json/
│ ├── __init__.py
│ ├── __main__.py
│ └── converter.py
└── tests/
├── __init__.py
├── test_converter.py
└── test_data/
├── sample.csv
├── sample.tsv
├── sample.xlsx
└── sample.txt
- Python 3.8+
- uv for virtual environment and package management
Clone the repository:
git clone https://github.com/humanrightsconnected/file2json
cd file2jsonSet up a virtual environment and install dependencies:
# Using Make (recommended)
make setup
# Or with uv (includes dev dependencies for testing/linting)
uv sync --extra dev# Basic usage
file2json sample.csv
# Specify output file
file2json sample.xlsx -o output.json
# Force file type
file2json ambiguous_file -t csv
# Get help
file2json --helpfrom file2json.converter import read_file, convert_to_json
# Read a file
data = read_file('sample.xlsx')
# Convert to JSON string
json_str = convert_to_json(data)
# Or save directly to a file
convert_to_json(data, 'output.json')Run tests:
make testRun linting:
make lintFormat code:
make formatMIT License - See LICENSE file for details.