A simple PHP utility to convert CSV files into structured JSON format.
Supports optional headers, custom delimiters, and deduplication by email or ID.
- ✅ Custom CSV delimiter (
--separator=";") - ✅ Detects and validates required columns
- ✅ Works with or without header rows
- ✅ Deduplicates by email (
--unique-email) - ✅ Deduplicates by ID (
--unique-id) - ✅ Converts status codes to enum values
- PHP 8.3
- Composer
composer installRun the converter from CLI:
php bin/convert.php [options] <input.csv> <output.json>| Option | Description | Default |
|---|---|---|
--input-file="..." |
Path to input CSV file | data/input.csv |
--output-file="..." |
Path to output JSON file | data/output.json |
--separator=";" |
Field separator (e.g. , or ;) |
, |
--no-header |
Treat file as without a header row | header expected |
--unique-email |
Skip duplicate rows by email | false |
--unique-id |
Skip duplicate rows by ID | false |
Convert a CSV file with ";" as a delimiter, without a header, skipping duplicate emails and IDs, with custom filepaths.
- separator: ","
- header row: without header
- duplicates: skip
- input file: users.csv
- output file: users.json
php bin/execute.php \
--separator=";" \
--no-header \
--unique-email \
--unique-id \
--input-file=users.csv \
--output-file=users.jsonConvert a CSV file with default settings:
- separator: ","
- header row: expected
- duplicates: kept
- input file: data/input.csv
- output file: data/output.json
php bin/execute.phpThis project uses PHPUnit for unit testing.
vendor/bin/phpunit tests --testdox Also uses PHPStan for static analyzing.
vendor/bin/phpstan analyse src bin tests --level=max