# CSV to JSON

Python 3.10+ command-line converter. The runtime uses only the standard library.

```sh
python csv_to_json.py input.csv output.json
python csv_to_json.py input.tsv output.json --delimiter tab
python csv_to_json.py input.csv output.json --delimiter ";" --encoding cp1252
```

The first record supplies JSON object keys. Comma, semicolon, tab and pipe formats can be detected automatically. Detection is heuristic: use an explicit delimiter when the file is ambiguous, including single-column files. Quoted fields, embedded newlines, quotes, Unicode and an initial UTF-8 BOM are handled. Field values remain strings, preserving leading zeros and original numeric spellings. Empty fields remain empty strings. Empty files produce an empty JSON array.

Duplicate/blank headers, rows with the wrong number of fields and malformed quoting cause an error before an output file is created. Blank records are ignored. Existing output files are never overwritten. Errors go to stderr and return exit status 1.

Input is loaded in memory. The converter supports conventional CSV dialects, not every malformed or proprietary export format. It does not infer business types or execute formulas. Output is UTF-8 JSON. Use a new destination filename for every conversion.

Development check: install pytest in an isolated environment and run `python -m pytest -q`. Tests cover four delimiters, quoting, multiline values, Unicode, BOM, encodings, empty inputs, invalid rows/headers, overwrite prevention and CLI behavior.
