Skip to content

nimleaf/CsvToJsonConverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSV to JSON Converter

A simple PHP utility to convert CSV files into structured JSON format.
Supports optional headers, custom delimiters, and deduplication by email or ID.

Features

  • ✅ 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

Requirements

  • PHP 8.3
  • Composer

Installation

    composer install

Usage

Run the converter from CLI:

    php bin/convert.php [options] <input.csv> <output.json>

Options

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

Example

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.json

Convert 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.php

Running Tests

This 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages