# CSV to JSON: Turn Rows into Records

- Author: FastBankConvert (https://www.fastbankconvert.com)
- Published: 2026-03-19
- Updated: 2026-03-19
- Category: CSV, JSON and text output
- Canonical: https://www.fastbankconvert.com/blog/csv-to-json

> Convert CSV to JSON records: header names become keys, numbers stay numbers, empty cells become nulls, and quoted commas stay in one field.
To convert CSV to JSON, read the header row as a list of keys, then turn every later line into one object that pairs each key with its value. The result is an array of records. Use a real CSV parser so quoted commas stay in one field, and decide up front which columns are numbers.

## How do CSV header names become JSON keys?

Each name in the CSV header row becomes a key, and each data line becomes one JSON object holding those keys. A file with a header and three data lines turns into an array of three objects.

Header names often need tidying before they make good keys. Spaces, capital letters and punctuation work in JSON, yet they are awkward in code. A header like `Posting Date` is easier to use as `posting_date` or `postingDate`. Pick one style and apply it to every column.

Two header problems need fixing before conversion, not after:

- **Duplicate names.** Two columns called `Amount` produce one object with the same key twice. [RFC 8259, the JSON standard](https://www.rfc-editor.org/rfc/rfc8259), says names should be unique and warns that parsers handle duplicates differently: some keep the last value, some raise an error.
- **No header at all.** A headerless file has nothing to name the keys. Add names first, or the converter will invent keys like `field1`.

### A worked example

These example lines, a header and three records made up for illustration, come from a converted statement:

```
Date,Description,Amount,Reference
2026-05-02,"GREEN LEAF CAFE, DOWNTOWN",-8.40,000731
2026-05-03,PAYROLL,1850.00,
2026-05-04,"ROOF REPAIR ""PHASE 2""",-640.00,000732
```

Converted with the rules in the next sections, they become:

```json
[
  { "date": "2026-05-02", "description": "GREEN LEAF CAFE, DOWNTOWN", "amount": -8.40, "reference": "000731" },
  { "date": "2026-05-03", "description": "PAYROLL", "amount": 1850.00, "reference": null },
  { "date": "2026-05-04", "description": "ROOF REPAIR \"PHASE 2\"", "amount": -640.00, "reference": "000732" }
]
```

Read the objects field by field. The comma in the first description stayed inside the string. The empty reference on the payroll line became `null`. The doubled quotes in the third line became escaped quotes in JSON. The references kept their leading zeros because they are strings.

## Numbers, text and empty cells in CSV to JSON output

Every CSV value is text, so the converter has to choose a JSON type for each column. Amounts should become numbers, identifiers with leading zeros should stay strings, and empty cells should become `null`. A converter that guesses per cell instead of per column gives you a mix of types in one field.

Set the type by column:

| Column | JSON type | Why |
| --- | --- | --- |
| Amount, balance | Number | Scripts add and compare them |
| Date | String in YYYY-MM-DD | JSON has no date type |
| Reference, account, check number | String | Leading zeros and long digit runs must survive |
| Description | String | Free text |
| Any empty cell | `null` | Shows that no value was given |

An empty cell and an empty string mean different things. `null` says the bank printed nothing. `""` says there was a value and it was blank. Most consumers expect `null` for a missing reference.

Watch for literals too. The standard requires `true`, `false` and `null` to be lowercase, so a CSV cell holding `NULL` or `True` should be mapped on purpose, not passed through as text by accident.

## Quoted commas and line breaks in a CSV to JSON conversion

Splitting each line on commas breaks the conversion as soon as a field holds a comma, a quote or a line break. [RFC 4180, the CSV format note](https://www.rfc-editor.org/rfc/rfc4180), puts such fields in double quotes and writes a quote inside them as two quotes. A proper parser follows those rules, and a one-line split does not.

Three cases to test with any converter:

1. A description with a comma inside quotes, like the cafe line in the example.
2. A description with doubled quotes, like the roof repair line.
3. A description that runs over two physical lines inside quotes.

The third case is the one that catches people. One record spans two lines of the file, so a line-by-line reader makes two broken objects from it. [Why line breaks in CSV cells split one record across rows](/blog/csv-line-breaks-in-cells) explains how those breaks get in and how to spot them.

## Are money amounts safe in a CSV to JSON converter?

Small amounts with two decimals are safe as JSON numbers for display and simple totals. Long identifiers are not. RFC 8259 notes that integers are exact across implementations only up to 2 to the power of 53 minus 1, so a 19-digit card reference written as a number can come back altered.

Practical rules for statement data:

- Keep amounts as numbers if the reader only adds and displays them.
- Store amounts as decimal strings, such as `"-8.40"`, if a system will do accounting arithmetic on them.
- Always keep references, account numbers and check numbers as strings.
- Strip currency symbols and thousands separators before conversion, or the value will not parse as a number at all.

## CSV files that need a different JSON shape than an array of records

A flat array of records fits a flat table. It fits poorly when the CSV is a flattened version of nested data, such as an invoice with header fields repeated on every line item. Converting that row for row gives you the invoice number fifty times instead of one invoice with fifty lines.

Group such files into nested objects instead: one object per invoice, with its line items in an array. The table you start from usually comes out of a PDF, and [pulling invoice line items from a PDF into Excel](/blog/pdf-invoice-line-items-to-excel) shows how those repeated header columns arise. Going the other way, from nested JSON back to rows, is covered in [flattening JSON records into CSV rows](/blog/json-to-csv).

If your source is a bank statement PDF, FastBankConvert is built to hand back JSON directly as well as CSV, so there would be no CSV stage to convert. It has not launched yet, and [getting started with FastBankConvert](/get-started) puts you on the list for trial conversions.
