Skip to content
K Knidox Search…
Computer Science · Data

CSV to JSON Converter

Turn CSV rows into a JSON array of objects, or flatten JSON back into CSV — quoted commas and all.

Direction
85 chars
Try an example — tap to load
JSON output
[
  {
    "name": "Ada",
    "role": "Engineer",
    "quote": "Loves math, logic"
  },
  {
    "name": "Grace",
    "role": "Admiral",
    "quote": "Says \"hello world\""
  }
]

This converter goes both ways. CSV → JSON reads the header row as keys and turns each following row into an object, so name,role over Ada,Engineer becomes [{ “name”: “Ada”, “role”: “Engineer” }]. JSON → CSV reverses it: object keys become the header row and each object becomes one line.

What CSV and JSON are for

CSV (comma-separated values) is a flat, spreadsheet-friendly table: one line per row, fields split by commas, and usually a header row naming the columns. JSON (JavaScript Object Notation) is the structured format that APIs and code prefer, where an array of objects maps each column name to a value. Converting between them lets you move data from a spreadsheet export into an application, or turn an API response into something you can open in Excel or Google Sheets.

How the conversion works

Going CSV → JSON, the first line is treated as the header and its cells become the object keys; every later line becomes one object, matching each cell to the key in the same position. Going JSON → CSV, the converter scans every object to build the union of all keys as the header row, then writes each object as a line, filling in an empty cell where a key is missing. Fields that contain a comma, a quote, or a line break are wrapped in double quotes, and any quote inside is doubled so nothing breaks the columns.

  1. 1
    Keep CSV → JSON selected. The default direction reads CSV and outputs a JSON array.
  2. 2
    Paste your CSV with a header row. For example name,role on the first line, then Ada,Engineer below it.
  3. 3
    Let the header become keys. name and role turn into the keys of every object in the array.
  4. 4
    Check quoted fields. A cell like "Loves math, logic" keeps its comma because it is wrapped in quotes.
  5. 5
    Copy the JSON. The output is a pretty-printed array: [{ “name”: “Ada”, “role”: “Engineer” }]. Use Copy to grab it.

CSV formatting rules

The conventions this converter follows when reading and writing CSV.

RuleWhat it means
Header rowThe first line names the columns; those names become the JSON keys.
Comma separates fieldsEach unquoted comma starts a new field on the row.
Quote fields with commasWrap a field in double quotes when it contains a comma, so it stays one cell.
Quote fields with line breaksA field holding a newline must be quoted so the row is not split early.
“” escapes a quoteInside a quoted field, two double quotes stand for one literal double quote.

When to use each direction

Use CSV → JSON when you have a spreadsheet or database export and need structured data for code, a config file, or an API request. Use JSON → CSV when an API or app hands you a JSON array and you want to open it in a spreadsheet, share it with non-developers, or import it somewhere that only accepts CSV. Both directions assume a single header row: CSV → JSON needs one to name the keys, and JSON → CSV writes one from the object keys. If your objects have different sets of keys, JSON → CSV merges them all into the header so no column is lost.

How are commas inside a field handled?
A comma only splits fields when it is outside quotes. Wrap the value in double quotes — like "Loves math, logic" — and the whole thing stays one cell that becomes a single JSON value.
Does the CSV need a header row?
Yes, for CSV → JSON. The first line is read as the column names, and those names become the keys of every object. Without a header the tool cannot label the values.
How are double quotes escaped?
Inside a quoted field, a literal double quote is written as two double quotes (“”). So "Says ""hello world""" decodes to Says “hello world”, and the reverse direction re-doubles them.
What happens if rows have different numbers of columns?
Going CSV → JSON, missing cells become empty strings and any extra cells beyond the header are ignored. This keeps every object aligned to the header keys.
How does JSON → CSV pick the columns?
It scans every object and takes the union of all keys, in first-seen order, as the header row. Objects missing a key get an empty cell for that column, so no data is dropped.
What JSON shape does the converter expect?
A top-level array of flat objects, like [{ “name”: “Ada” }]. If an object holds a nested object or array, that value is written into the cell as its JSON text rather than split into more columns.