Clever Quest Lab Tools

CSV to JSON Converter

Convert CSV to JSON, or JSON back to CSV, right in your browser. Paste text or open a file: nothing is uploaded. The reader handles quoted fields and line breaks inside fields, detects the delimiter and can turn numbers and booleans into real JSON values.

Input

Direction
Paste or type here, or drop a file onto the box.
The file is read by your browser only. It is not uploaded.

Options

Output

—

The conversion runs locally in your browser. Your data is not uploaded.

Preview

—

The preview shows the first 100 rows. Numbers and booleans are set in a monospace font and null in italics. A row marked with ⚠ has a different number of fields than the header: its missing fields become null and its extra fields get the keys column_N, where N is the field number.

Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves your settings and input text (up to 100,000 characters) on this device; Clear empties the saved text.

Added · Updated : same CSV reader and column names as the CSV to SQL converter and CSV viewer

How to use the CSV to JSON converter

  1. Choose the direction: CSV → JSON or JSON → CSV.
  2. Paste your data into the input box, or open a local file with the file button or by dropping it onto the box. A file ending in .json, .ndjson or .jsonl switches the direction to JSON → CSV.
  3. Leave the delimiter on Auto-detect, or pick comma, semicolon, tab or pipe yourself. The status line names the delimiter that was used.
  4. Set the options: whether the first row is a header, whether numbers and booleans are inferred, what an empty field becomes, the output format and the indentation.
  5. Read the status line, the warnings and the preview table, then press Copy or Download.

The result updates while you type. Above about 1 MB of input, press Convert instead; the boxes then show only part of the data, but Copy and Download give the complete result. Files are read as UTF-8 text.

How it works

The CSV reader follows RFC 4180, the document that describes the common CSV format:

Delimiter detection. The first 50 records (at most 64 KB) are read four times, with a comma, a semicolon, a tab and a pipe. For each delimiter the tool finds the most common number of fields and the share of records that have it; a delimiter that gives fewer than two fields is left out. The largest share wins, then the larger number of fields, then the order comma, semicolon, tab, pipe. When no delimiter gives two fields, the text is read as one column.

Type inference. A field becomes a JSON number only when it is written the way JSON writes numbers (an optional minus sign, digits without a leading zero, an optional fraction and exponent) and turning it into a number and back gives the same value. Everything else stays text:

Field textJSON valueReason
42, -0.5, 1.5042, -0.5, 1.5plain numbers
1e31000exponent notation
007, +5"007", "+5"leading zero, plus sign
1,5, 0x1F, 555-0100textnot JSON numbers
12345678901234567890textwhole numbers outside ±9,007,199,254,740,991 (253 − 1) would be rounded
true, FALSEtrue, falsebooleans, in any letter case
empty fieldnull or ""your choice

A decimal with more digits than a number can hold exactly also stays text. Quotes do not change the type unless you tick Keep quoted fields as text; then a quoted "42" stays text and a quoted empty field stays an empty string. With inference off, every value is text.

Header names become the object keys, without spaces at their start and end. An empty name becomes column_N, where N is the column number, and a repeated name gets a suffix: name, name_2, name_3. Names that differ only in letter case, such as id and ID, count as repeated, because SQL databases treat them as one column. Both cases are reported. Without a header row the keys are column_1, column_2 and so on.

Rows with the wrong number of fields are listed with their line number and marked in the preview. Missing fields become null; an extra field gets the key column_N for its field number. In array-of-arrays output a row keeps exactly the fields it has.

The CSV to SQL converter and the CSV viewer read CSV with the same code, so with the default options a file gets the same delimiter and the same column names on all three pages.

Examples

Example 1 — quoted fields. Press Load example in CSV → JSON mode:

id,name,joined,active,score,notes
007,"Smith, John",2024-03-15,true,91.5,"Said ""hello"""
8,Anna Lee,2023-11-02,FALSE,,"Line 1
Line 2"

The status line reports 2 rows, 6 columns and a comma delimiter. The ID with a leading zero stays text and the empty score becomes null:

[
  {
    "id": "007",
    "name": "Smith, John",
    "joined": "2024-03-15",
    "active": true,
    "score": 91.5,
    "notes": "Said \"hello\""
  },
  {
    "id": 8,
    "name": "Anna Lee",
    "joined": "2023-11-02",
    "active": false,
    "score": null,
    "notes": "Line 1\nLine 2"
  }
]

Example 2 — semicolons. The three lines id;price;ok, 007;1.50;true and 8;;false are detected as semicolon-separated. With minified output the result is [{"id":"007","price":1.5,"ok":true},{"id":8,"price":null,"ok":false}].

Example 3 — uneven rows. The lines a,b, 1,2,3 and 4 give two warnings, “Line 2: 3 fields, expected 2.” and “Line 3: 1 field, expected 2.”, and the minified output [{"a":1,"b":2,"column_3":3},{"a":4,"b":null}].

Example 4 — JSON to CSV. The input [{"a":1,"b":"x,y"},{"a":2,"c":"he said \"hi\""}] has three different keys, so the CSV gets three columns:

a,b,c
1,"x,y",
2,,"he said ""hi"""

Array of objects, array of arrays or NDJSON?

JSON to CSV: what happens to nested data

For an array of objects the columns are all keys that occur in any object, in the order in which they first appear; an object that lacks a key gets an empty field. An array of arrays is written row by row without a header line. null becomes an empty field. A nested object or array is not spread over several columns: it is written as JSON text in one cell.

A field is put in double quotes when it contains the delimiter, a quote, a line break, or a space at its start or end, and every quote inside it is doubled. Records end with CRLF, as RFC 4180 specifies, or with LF if you choose it.

Frequently asked questions

Why is a value that looks like a number in quotes?

Because it would not survive as a JSON number. Leading zeros (ZIP codes, IDs), a plus sign, a decimal comma, thousands separators and whole numbers beyond ±9,007,199,254,740,991 are kept as text so that no digit is lost. To keep every value as text, turn type inference off.

How do I convert a semicolon- or tab-separated file?

Open it as it is. Auto-detect recognises semicolons, tabs and pipes as well as commas, and the status line shows which one it chose. A decimal comma, as in 1,5, is not a JSON number, so such values stay text.

Why do I get a warning about the number of fields?

A record has more or fewer fields than the header. The usual causes are a delimiter or a line break inside a field that is not quoted. Check the line named in the warning.

How large a file can it convert?

Files up to 50 MB are accepted. The practical limit is the memory of your device, because the input and the output are both held in the browser.

Sources