# CSV to JSON: parsing rules, string values and ragged rows

> How this converter reads CSV (comma only, first row as header, quotes per RFC 4180 with some leniency), why every value stays a string, and what happens to short rows, long rows, duplicate headers and a byte-order mark.

- Tool: [CSV to JSON Converter](https://toolsg.com/en/csv-to-json)
- Language: en (available: en, zh, ms, ta)
- Last verified against official sources: 2026-10-19
- Source site: ToolSG — a planning guide, not official or financial advice. Cite the agencies listed under Sources.

## Key figures at a glance

| Fact | Value | Source |
| --- | --- | --- |
| Delimiter | Comma only — A semicolon-separated file is not split; each line becomes one column. | [IETF — RFC 4180](https://www.rfc-editor.org/rfc/rfc4180.html) |
| Header row | Always the first row — Its cells become the JSON keys of every record; there is no option to turn headers off. |  |
| Value types | Every value is a string — 30 becomes "30", 007 stays "007", 12.50 stays "12.50". |  |
| Quoted fields | Commas, line breaks and "" inside quotes are read correctly — A quote only opens a quoted field at the start of the field. |  |

## What the converter does

Paste CSV and the right-hand box shows a JSON array with one object per data row, indented with two spaces. It updates as you type, nothing is uploaded, and a Download link (`converted.json`) appears once there is output. Whitespace-only input gives empty output.

Example input `name,city,age` / `Mei,Singapore,30` / `Ali,Johor,25` gives:

```json
[
  { "name": "Mei", "city": "Singapore", "age": "30" },
  { "name": "Ali", "city": "Johor", "age": "25" }
]
```

(The page expands each object over several lines.) Note `"30"`: numbers, booleans and empty cells are all strings, because CSV carries no types. Leading zeros and trailing decimals therefore survive (`007`, `12.50`), and values such as `1e3` or `0x1F` are not interpreted. Convert in your own code with `Number(value)` where you need numbers.

## Parsing rules

RFC 4180 is an informational memo, not a standard, and real-world files bend it. This parser follows its main rules and is more lenient in a few places:

- Records end at a line break. CRLF, a bare CR and LF are all accepted; a single trailing newline does not create an empty row. Line breaks inside quotes are kept and normalised to `\n`.
- A field is quoted only if its first character is `"`. Inside quotes, `""` is one literal quote and commas and line breaks are literal.
- A quote in the middle of an unquoted field is kept as text: `x"y` gives `x"y`. RFC 4180 does not allow this, but many exporters produce it.
- Characters after a closing quote are appended: `"x"y` gives `xy`.
- An unclosed quote stops the conversion with "A quoted field was never closed — check for a stray double quote."
- Spaces are part of the field. `a, b` gives the key `" b"` and `" 1 "` keeps its spaces; nothing is trimmed.

## Ragged rows, headers and blank lines

| Input | Result |
| --- | --- |
| row with fewer cells (`a,b` then `1`) | missing cells become `""` |
| row with more cells (`1,2,3` under `a,b`) | extra cells are dropped silently |
| duplicate headers (`a,a` then `1,2`) | the later column overwrites: `{"a":"2"}` |
| empty header cell (`,b`) | key `column_1` (position-based) |
| blank line between rows | a record whose values are all `""` |
| header row only | `[]` |
| UTF-8 byte-order mark at the start | kept: the first key becomes `"﻿name"` |
| semicolon-separated file | one key (`a;b`) with the whole row as its value |

The last two matter in practice. Strip a byte-order mark before pasting if your export adds one, or the first column will not match its expected name. For semicolon or tab files, replace the delimiter or use [TSV to JSON](https://toolsg.com/en/tsv-to-json).

> **Tip:** After converting, check one row with a comma, a quote and a line break in the same cell. If that row comes through intact, the rest will too.

## Common mistakes

- Expecting numbers or `null`: you get strings, including `""` for empty.
- Pasting a file whose first row is data, not a header; the first record becomes the keys.
- Not noticing that surplus cells were dropped because the header was shorter.
- Counting on duplicate column names; later ones silently replace earlier ones.
- Assuming that the page enforces equal field counts. RFC 4180 says each line should have the same number; this tool accepts uneven rows.

## Related tools

Go back with [JSON to CSV](https://toolsg.com/en/json-to-csv), read tab-separated data with [TSV to JSON](https://toolsg.com/en/tsv-to-json), check the result with the [JSON validator](https://toolsg.com/en/json-validator), or explore it in the [JSON viewer](https://toolsg.com/en/json-viewer).

## Frequently asked questions

**Is my data uploaded anywhere?**

No. The conversion runs entirely in your browser using JavaScript. Nothing you paste leaves your device, is logged, or is stored on a server.

**How large a document can it handle?**

The limit is your browser's memory rather than any server quota. Documents of a few megabytes convert without trouble; very large files may make the page briefly unresponsive while it works.

**What happens to nested data?**

Formats that have no concept of nesting store nested values as a JSON string inside the cell, so nothing is silently discarded and the structure can be recovered.

**Does it handle quotes and commas inside fields?**

Yes. Parsing follows RFC 4180, so quoted fields containing commas, escaped double quotes, and line breaks inside a field are all read and written correctly.


## Sources

- [IETF — RFC 4180, Common Format and MIME Type for CSV Files](https://www.rfc-editor.org/rfc/rfc4180.html) — Informational (not a standard): fields, quoting rules, optional header.
- [IETF — RFC 8259, The JSON Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259.html) — The JSON output.
