# CSV to JSON converter

> Convert RFC 4180 CSV text into a JSON array of objects using the first row as keys.

Live HTML: https://plaintools.io/dev/csv-to-json-converter

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

You have spreadsheet or CSV data and need structured JSON records.

## When not to

CSV files with no header row, non-delimited text, or multi-table composite sheets.

## Inputs

- **csv:** CSV text with a header row followed by data rows.
- **parseTypes:** Boolean (default true). When true, auto-converts valid numbers, booleans, and null.
- **minify:** Boolean (default false). When true, emits compact single-line JSON; else 2-space indented.

## Outputs

- **json:** JSON array of objects.
- **columns:** Array of header column names.
- **rowCount:** Number of data rows parsed.

## Steps

1. Parse CSV according to RFC 4180: track state inside/outside double quotes, handle escaped quotes `""` as a literal quote, handle commas as field delimiters, and CRLF / LF as row breaks.
2. Trim records, dropping empty trailing lines. Require at least two rows (one header row and at least one data row).
3. Extract headers from the first row. Normalize duplicate headers by suffixing `_2`, `_3`, etc., and replace empty headers with `column_N`.
4. Map each subsequent data row to an object keyed by header columns. Extra fields beyond column count become `_extra_1`, etc. Missing fields default to empty string.
5. If parseTypes is enabled: parse "true"/"false" to booleans, "null" to null, and unquoted numeric strings to numbers (excluding strings with leading zeroes).
6. Serialize to JSON: `JSON.stringify(records, null, 2)` (or compact if minify is requested) with a trailing newline.

## FAQs

### Is my CSV uploaded to a server?

No. The CSV is parsed directly in this tab using client-side JavaScript. No data is sent over the network or logged anywhere.

### Does the CSV require a header row?

Yes. The first line of the CSV must contain column headers, which become the keys of each JSON object in the resulting array.

### How does this tool handle commas and newlines inside quotes?

It follows standard RFC 4180 rules. Fields enclosed in double quotes can contain commas, line breaks, and escaped double quotes ("").

### What does auto-detect numbers and booleans do?

When enabled, unquoted text matching numbers (e.g. 42 or 3.14) or booleans (true, false, null) are parsed into JSON numbers and booleans rather than strings. Strings with leading zeroes (like zip codes or phone numbers) remain strings.

### Can I convert JSON back to CSV?

Yes. Use our paired JSON to CSV converter to turn an array of JSON objects back into an RFC 4180 CSV spreadsheet.

### How do I convert CSV to JSON without this page?

Tokenize CSV according to RFC 4180: track quote state, treat doubled quotes as literal quotes, split on unquoted commas for fields and unquoted newlines for rows. The first row defines the keys. Map each subsequent row into an object where obj[headers[i]] = row[i]. If type coercion is enabled, parse numeric and boolean literals. Format with JSON.stringify(results, null, 2).

## Related tools

- [JSON to CSV converter](https://plaintools.io/dev/json-to-csv-converter.md) — HTML: https://plaintools.io/dev/json-to-csv-converter
- [YAML to JSON converter](https://plaintools.io/dev/yaml-to-json-converter.md) — HTML: https://plaintools.io/dev/yaml-to-json-converter
- [Hash generator](https://plaintools.io/dev/hash-generator.md) — HTML: https://plaintools.io/dev/hash-generator
