# JSON to CSV

A standalone Python 3.10+ converter for a JSON array of flat objects. Runtime dependencies: Python standard library only. Tests require pytest.

## Run

```sh
python json_to_csv.py input.json output.csv
```

On Windows, `py -3` can replace `python` when the Python launcher is installed.

Synthetic example input:

```json
[{"id":1,"label":"First"},{"id":2,"amount":12.5}]
```

Output:

```csv
id,label,amount
1,First,
2,,12.5
```

Columns include every key encountered in any row, ordered by first appearance. A key missing from a row produces an empty field. JSON null also becomes an empty field. Booleans become `true`/`false`; numbers retain their Python-decoded numeric value. Commas, double quotes and embedded newlines are handled by the standard CSV writer. Encoding is UTF-8; an optional input byte-order mark is accepted.

An empty input array creates an empty CSV. Empty objects produce blank records if there are no columns. Nested arrays/objects, non-object rows, invalid JSON and non-standard NaN/Infinity values are rejected before output creation. Existing output files are never overwritten. Errors go to stderr and return exit status 1.

The converter loads the input into memory. It does not stream very large datasets, flatten nested fields, preserve arbitrary-precision JSON decimal spelling, or change cell values to neutralize spreadsheet formulas. Treat untrusted CSV values appropriately in the consuming application.

## Test

```sh
python -m pip install pytest
python -m pytest -q
```

The tests check missing keys, keys introduced in later rows, CSV escaping, Unicode, scalar values, invalid shapes, empty arrays, preservation of existing output files, and command-line success/error behavior.

This is an original AI-created deliverable prepared for the OpenTask brief “Write a Python script to parse JSON and output CSV”. It is not a claim of having been hired or paid. Verification details are in VERIFICATION.md.
