CSV 转 JSON 转换器

把 CSV 转成 JSON 并实时预览表格,正确处理带引号字段、内嵌逗号和换行,完全符合 RFC 4180。

Output

The CSV rules that trip people up

CSV looks simple but has a few sharp edges, all defined by RFC 4180:

  1. Values containing a comma must be quoted — Smith, John breaks without quotes
  2. Values containing a quote must be quoted, and the quote doubled — "He said ""hi"""
  3. Values containing a newline must be quoted
  4. The first row is the header by convention

This tool implements all four, so pasted CSV that looks broken in a text editor still parses correctly.

Example

name,role,year
Ada,Engineer,1815
Alan,Researcher,1912

becomes

[
  { "name": "Ada", "role": "Engineer", "year": "1815" },
  { "name": "Alan", "role": "Researcher", "year": "1912" }
]

Types are not inferred

Every value comes out as a string, because CSV has no type information. If you need numbers, booleans or nulls, cast them in code afterwards, or use a tool that supports typed columns.

For a quick conversion in JavaScript:

const rows = data.map(r => ({
  name: r.name,
  year: Number(r.year),
  active: r.active === "true",
}));

Command line

For large files, jq handles CSV with the @csv operator:

# CSV to JSON
cat data.csv | jq -R -s 'split("\n") | map(split(",")) | transpose | ...'

Or use csvjson if you have it installed — it handles types and headers properly.

Related

Going the other way? The JSON to CSV converter flattens an array of objects into spreadsheet-ready rows.

常见问题

Is my CSV uploaded to a server?

No. The parser runs entirely in your browser. Your data never leaves your device.

Why are all my values strings?

CSV has no type information — everything is text by definition. Cast the values in your code, or check for a tool that supports typed columns.

How does it handle quoted values with commas?

Correctly, per RFC 4180. A value wrapped in double quotes can contain commas, and a literal quote inside it is written as two doubled quotes.

What if my file uses semicolons instead of commas?

That is a tab-separated or semicolon-separated file, not standard CSV. Replace the separator in your export settings, or split the text on the semicolon before pasting.

Can it convert a large CSV file?

It handles files up to a few megabytes comfortably. For very large files, use a command-line tool such as csvjson or qsv, which stream rather than load everything into memory.