# CSV to JSON Zero-dependency CSV <-> JSON converter with delimiter/header detection. ``` python scripts/run.py csv2json data.csv python scripts/run.py csv2json data.csv --no-header python scripts/run.py csv2json data.tsv -d '\t' python scripts/run.py json2csv data.json echo 'a,b 1,2' | python scripts/run.py csv2json - ``` Pure Python stdlib (`csv` + `json`) — runs anywhere. --- name: csv-to-json display_name: CSV to JSON description: "Convert CSV to JSON and JSON arrays back to CSV, with automatic delimiter and header detection. Triggers: convert csv, csv to json, json to csv, parse csv, csv delimiter." --- # CSV to JSON Convert tabular CSV data to JSON (and JSON arrays back to CSV) from chat. ## When to use The user pastes CSV (or a `.csv`/`.json` file) and wants it as JSON objects, or has a JSON array they want flattened into CSV rows for a spreadsheet. ## How to use Run `scripts/run.py` with a mode: - `python scripts/run.py csv2json data.csv` — first row becomes object keys; delimiter auto-detected. - `python scripts/run.py csv2json data.csv --no-header` — emit an array of arrays. - `python scripts/run.py csv2json data.tsv -d '\t'` — force a delimiter. - `python scripts/run.py json2csv data.json` — JSON array of objects -> CSV with a header row. Read from stdin with `-`, e.g. `cat data.csv | python scripts/run.py csv2json -`. ## Pitfalls - Auto-detection samples the first 4KB; pass `-d` if a weird delimiter is guessed. - `json2csv` requires a top-level JSON array; objects use the union of all keys. - Tab delimiter on the shell: quote it as `-d '\t'` or pass an actual tab.
CSV to JSON by langbot-team
Convert CSV to JSON and JSON arrays back to CSV, with automatic delimiter and header detection.
Loading...