oktools

CSV to JSON & JSON to CSV Converter

Convert CSV to JSON and JSON back to CSV in your browser. Reads comma-, semicolon- and tab-separated (TSV) data, including Excel exports with a byte-order mark, with quoted fields and embedded line breaks handled as RFC 4180 describes. Pick the delimiter and quote character or let them be detected, keep the first row as the header or get arrays, and optionally detect numbers, booleans and null.

How it works

The CSV is read one character at a time rather than split on line breaks, because a quoted field may contain the delimiter, a doubled quote standing for a literal quote, or a line break, and all three must stay inside the field. A quote opens quoted mode only at the start of a field, so a value such as 5'10" inside an unquoted cell is taken as text. Unquoted fields are trimmed, quoted ones are kept exactly, blank lines are skipped, a Windows carriage return is dropped, and the UTF-8 byte-order mark Excel writes is removed so it does not end up inside the first header.

With Auto-detect the delimiter is whichever of comma, semicolon, tab and pipe appears most often in the first non-empty line, the first of those on a tie. With First row is header ticked, each later row becomes an object keyed by the header names: a short row is padded with empty strings, extra cells go into a __parsed_extra array, and a warning is listed for every row whose cell count differs from the header. Every cell is a string unless Detect numbers, booleans and null is ticked, which converts 42, -3.5, 1e3, true, false and null while keeping leading zeros and integers past 2^53 as text.

Going back, a JSON array of objects is written with a header made from the union of every object’s keys, in the order they are first seen, so a field that appears only in the third object still gets its own column and a missing value is an empty cell. An array of arrays is written row by row. A cell is quoted when it contains the delimiter, the quote character, a line break or leading or trailing whitespace, with any quote inside it doubled, and a nested object or array is written as its JSON text.

Examples

Convert CSV with a header row to JSON

The quoted city keeps its comma rather than spilling into a fourth cell, and age stays a string because nothing was asked to guess types. The status line reads 2 rows converted to JSON objects · comma delimiter detected.

CSV
name,age,city
Ann,34,Leeds
Bob,27,"Cardiff, Wales"
JSON
[
  {
    "name": "Ann",
    "age": "34",
    "city": "Leeds"
  },
  {
    "name": "Bob",
    "age": "27",
    "city": "Cardiff, Wales"
  }
]

Detect numbers, booleans and null

With the box ticked, true, 9.5, 20 and null take their JSON types while 007 keeps its leading zero as text. An empty cell stays an empty string rather than null; only the word null becomes null.

CSV
sku,in_stock,price,notes
007,true,9.5,null
12,false,20,
JSON
[
  {
    "sku": "007",
    "in_stock": true,
    "price": 9.5,
    "notes": null
  },
  {
    "sku": 12,
    "in_stock": false,
    "price": 20,
    "notes": ""
  }
]

Read a semicolon-separated Excel export

Semicolons outnumber commas on the first line, so the semicolon is chosen and the decimal comma in 1,5 stays inside its cell. Type detection would leave 1,5 as text as well, since it is not a JSON number.

CSV
name;amount
Ann;1,5
Bob;20
JSON
[
  {
    "name": "Ann",
    "amount": "1,5"
  },
  {
    "name": "Bob",
    "amount": "20"
  }
]

Convert JSON with uneven objects to CSV

The header is the union of both objects’ keys, so phone gets a column even though the first object lacks it, and the missing values are empty cells rather than a shifted row.

JSON
[{"name":"Ann","email":"ann@example.com"},{"name":"Bob","phone":"0117 496 0000"}]
CSV
name,email,phone
Ann,ann@example.com,
Bob,,0117 496 0000

Supported formats

  • RFC 4180 CSVQuoted fields with embedded delimiters, doubled quotes and line breaks, CRLF or LF line endings and a trailing newline. A quote in the middle of an unquoted field is literal.
  • Delimiters and quote charactersComma, semicolon, tab and pipe, detected from the first line or chosen, with " or ' as the quote. Tab covers TSV pasted from a spreadsheet, semicolon the Excel default in much of Europe.
  • Excel exportsA leading UTF-8 byte-order mark is stripped before parsing, so the first header is read as name rather than as an invisible character followed by name.
  • JSON shapesCSV becomes an array of objects with a header, or an array of arrays without one, pretty-printed with two-space indentation. JSON must be a non-empty array of objects or of arrays to become CSV.
  • Typed values on request42, -3.5, 1e3, true, false and null become numbers, booleans and null; leading zeros, integers past 2^53 and everything else stay strings.

Use cases

  • Turn a spreadsheet export into fixture dataExport the sheet as CSV, paste it, and get an array of objects to seed a test, a mock endpoint or a local database.
  • Load a CSV into a script without a parserPaste once, copy the JSON and read it with JSON.parse or json.load instead of handling quoting and line breaks yourself.
  • Flatten an API response for a spreadsheetPaste the JSON array an endpoint returns and open the CSV in Excel, Numbers or Google Sheets, with every key as a column.
  • Find out why a CSV is rejectedRagged rows are listed by number under the output and an unclosed quote is named, which is usually the whole explanation.
  • Move data between systemsExport a table as semicolon- or tab-separated text, convert it, and import the JSON documents elsewhere, or the reverse.

Limitations

  • Nested JSON is not flattenedAn object or array inside a row is written into its cell as JSON text, not spread into address.city columns. Flatten the data first if the spreadsheet needs one column per field.
  • No dates or custom typesDetection covers numbers, booleans and null only. A date stays a string in the output, and no column can be given a type by hand.
  • Delimiter detection reads one lineThe choice is made from the first non-empty line and applied throughout, and only comma, semicolon, tab and pipe are candidates. Pick the delimiter yourself for another separator or an unusual first line.
  • Text in a text boxThere is no file picker and no streaming, so a file is pasted rather than opened. A very large export is better handled with csvkit or a short script.
  • Whitespace around unquoted values is trimmedA cell written as a becomes a going to JSON, as spreadsheet parsers do; going to CSV such values are quoted so they survive a round trip. Quote a cell in the input if its spaces matter.

Frequently asked questions

How do I convert CSV to JSON?

Paste the CSV in with CSV to JSON selected. With "First row is header" ticked the first row is read as the field names and every row after it becomes one object in an array, which is the shape almost every API and script expects; untick it to get a plain array of arrays instead. The result appears as you type, and a row with more or fewer cells than the header is listed under the output rather than silently padded or cut.

Can it convert JSON back to CSV?

Yes — switch the direction. A JSON array of objects is flattened to a header row built from the union of every key, so rows that are missing a field still line up under the right column instead of shifting everything along by one. An array of arrays is written out row by row as it is.

Which delimiters are supported?

Comma, semicolon, tab and pipe, and the delimiter is detected from the first line unless you pick one. The quote character can be " or '. That covers semicolon-separated files — the default Excel export in much of Europe — tab-separated (TSV) data pasted straight out of a spreadsheet, and the UTF-8 byte-order mark Excel puts at the start of a file, which is stripped before parsing.

How are commas, quotes and line breaks inside a value handled?

As RFC 4180 specifies. A field wrapped in quotes may contain the delimiter, a newline or a doubled quote character standing for a literal quote, and all of that is parsed rather than split blindly on commas. A quote in the middle of an unquoted value, such as 5'10", is taken literally. Writing CSV works the same way round: any value that needs quoting gets it.

Why are my numbers coming out as strings?

Because CSV has no types — every field is text, and guessing which columns are numbers is how leading zeros disappear from postcodes and how long IDs turn into rounded floats. By default values are kept as written so nothing is silently corrupted. Tick "Detect numbers, booleans and null" to convert cells that look like 42, 3.5, true, false or null; values with leading zeros and integers too long for a JavaScript number are still left as text.

Is my spreadsheet data uploaded anywhere?

No. The whole tool is JavaScript running in your own browser, so nothing you type or paste is sent over the network, written to a log or attached to an analytics event. You can confirm it by opening the network tab and watching it stay empty while you work.