How to Convert CSV to JSON

Learn CSV headers, delimiters, array-of-objects output, quoted fields, and edge cases so your spreadsheet data becomes clean JSON every time.

By Generatr Team

CSV is a grid: rows and columns of text. JSON is nested structure: objects, arrays, strings, numbers, booleans, and null. Converting CSV to JSON means deciding how each row becomes a record and how each column becomes a field — then handling the messy parts spreadsheets always hide (commas inside quotes, missing cells, weird delimiters).

This guide covers headers as keys, delimiter choice, the usual array-of-objects shape, edge cases that break naive split-on-comma code, and a clean workflow with a browser tool. When you want the conversion done in one paste, open the free CSV to JSON converter.

APIs, config files, and front-end apps usually want JSON. Exports from Excel, Google Sheets, databases, and CRMs usually give CSV. Bridging them correctly once saves hours of “why is field 3 always wrong?” debugging later.

Free tool

Use the CSV to JSON Converter now

Open the interactive csv to json converter in your browser — free, instant, no signup.

Open CSV to JSON Converter

What Are CSV and JSON, Structurally?

CSV (comma-separated values) is a plain-text table. The first row is often headers. Each following row is a record. Fields are separated by a delimiter (commonly comma, sometimes semicolon, tab, or pipe).

JSON (JavaScript Object Notation) is a structured data format. After conversion you almost always want an array of objects, one object per data row, with property names taken from the header row.

Minimal example

CSV:

name,age,city
Ada,36,London
Lin,29,Taipei

JSON (array of objects):

[
  { "name": "Ada", "age": "36", "city": "London" },
  { "name": "Lin", "age": "29", "city": "Taipei" }
]

Notice age is still a string unless your converter coerces types. Many tools keep everything as strings by default so “00123” zip codes do not become numbers and lose leading zeros.

After conversion, pretty-print and validate with the free JSON formatter validator and our JSON formatter guide.

How Do CSV Headers Become JSON Keys?

With “first row is headers” enabled, each header cell becomes a property name on every object. Row 2’s cells map positionally to those names.

Header hygiene

  • Unique names — duplicate headers overwrite or collide depending on the parser; rename before convert
  • Stable names — spaces and punctuation are legal in JSON keys but annoying in code; prefer first_name or firstName
  • No empty header — blank column titles become empty-string keys or auto-generated names; fix the sheet

No-header mode

If the file has no header row, converters often emit arrays of arrays, or invent keys like column1, column2. Array-of-arrays is faithful to the grid but painful for most apps. Prefer adding a header row once in the spreadsheet, then converting to objects.

Column order

JSON object key order is usually preserved by modern engines for string keys you insert in order, but your program should look up fields by name, not by “third key.” CSV order only matters for mapping cells to header names at parse time.

Which Delimiter Should You Use?

“CSV” is a family of dialects, not one strict law. Wrong delimiter is the #1 silent failure: you get one giant field per line instead of columns.

DelimiterCommon when
Comma ,U.S./UK Excel exports, many APIs
Semicolon ;Locales where comma is the decimal mark
TabTSV exports, some database dumps
Pipe |Data that already contains many commas

Auto-detection

Good converters sample the first lines and guess. If your data has more semicolons than commas in the header line, semicolon is a strong guess. Always glance at column count in the preview: 1 column on a 10-field export means wrong delimiter.

Decimals and locales

European-style 1.234,56 numbers inside semicolon-delimited files are still text to a CSV parser. Type coercion rules vary. Keep them as strings unless you deliberately parse numbers with the right locale rules.

Paste into the free CSV to JSON converter, switch delimiters, and watch the live column count until it matches your sheet.

Why Is Array of Objects the Default Output?

Most web and backend code wants a list of records: [{...}, {...}]. That shape maps cleanly to database rows, table UIs, and map/filter loops.

Other shapes you might see

  • Array of arrays — no header semantics; good for pure grids
  • Column-oriented object{ "name": ["Ada","Lin"], "age": ["36","29"] } for some analytics pipelines
  • Nested JSON — only if a column already contains JSON text or you post-process paths like address.city

Type coercion choices

Optional parsers turn true/false/null/numbers into JSON types. That helps APIs but can damage:

  • IDs with leading zeros
  • Phone numbers and ZIP+4
  • Large integers past Number.MAX_SAFE_INTEGER in JavaScript

When in doubt, keep strings and coerce in your application with explicit rules. After convert, run the free JSON formatter validator to confirm the document is parseable before you ship it.

What Edge Cases Break Naive CSV Parsing?

Never parse production CSV with line.split(',') alone. Real files use RFC 4180-style quoting.

  • Commas inside quotes"Smith, Ada",36 is two fields, not three
  • Embedded newlines — a quoted field can span lines; row ≠ one line always
  • Escaped quotes"She said ""hi"""She said "hi"
  • Empty fieldsa,,c is three fields; middle is empty string
  • Trailing delimitera,b, may mean a third empty field
  • UTF-8 BOM — Excel sometimes prefixes \uFEFF; your first header becomes "\uFEFFname" if you do not strip it
  • Mixed line endings\r\n vs \n; parsers should accept both

Encoding

Save CSV as UTF-8 when non-ASCII characters matter. Latin-1 misread as UTF-8 produces mojibake in JSON strings. If you must transport binary alongside JSON, that is a different problem — see how Base64 works with the Base64 tool.

For query strings and special characters in URLs (not CSV itself), use the free URL encoder decoder and our URL encoding guide.

How Do You Convert CSV to JSON Online?

Export cleanly, paste or upload, set dialect options, preview rows, then copy or download JSON.

  1. Open the free CSV to JSON converter.
  2. Paste CSV text (or load the file if the tool supports upload).
  3. Confirm whether the first row is headers.
  4. Set delimiter: comma, semicolon, tab, or pipe to match the file.
  5. Check live preview: row count, column count, and sample objects.
  6. Copy the JSON or download the file for your app or API.
  7. Validate formatting with a JSON formatter if you need indented output or error locations.

Pre-clean in the spreadsheet

Delete empty trailing columns, fix duplicate headers, and ensure one header row only. Five minutes in Sheets/Excel prevents twenty minutes of key renames in code.

What Are Common CSV-to-JSON Mistakes?

Watch for these when the output “looks fine” but breaks later.

  • Wrong delimiter — one property containing the entire line
  • Headers treated as data — first object is {"0":"name","1":"age"} style noise or header text as values
  • Unquoted commas — columns shift right for some rows only
  • Assuming all rows have the same width — short rows need empty defaults for missing trailing cells
  • Number coercion on IDs — leading zeros and big integers damaged
  • Not validating JSON — trailing commas or bad escapes from a buggy converter

This guide is educational. For regulated data (PII, health, finance), convert locally and follow your organization’s data-handling rules — browser tools still run on a machine you must trust.

Step-by-Step Instructions

  1. 1Open the free CSV to JSON converter on Generatr.
  2. 2Paste your CSV text or otherwise load the tabular file.
  3. 3Enable first-row headers when your file includes column names.
  4. 4Choose the correct delimiter (comma, semicolon, tab, or pipe).
  5. 5Preview row and column counts to confirm the dialect is right.
  6. 6Generate array-of-objects JSON and copy or download it.
  7. 7Validate or pretty-print the result in a JSON formatter if needed.
  8. 8Fix header names and quoting issues in the source sheet if fields look wrong.

Frequently Asked Questions

How do you convert CSV to JSON?+

Treat the first row as property names when present, split each data row into fields with a real CSV parser (respecting quotes), and emit an array of objects. Online converters do this in one paste; libraries do it in code for pipelines.

Why does my CSV become one column in JSON?+

The delimiter is probably wrong. Semicolon-separated European exports often fail if you parse as comma-separated. Switch delimiter until the column count matches your spreadsheet.

Should ages and prices stay strings in JSON?+

It depends. Strings are safest for IDs, ZIPs, and leading zeros. Coerce to numbers only when you need math and values are true numeric fields within safe ranges for your language.

How are commas inside fields handled?+

Proper CSV wraps such fields in double quotes. A standards-aware parser treats commas inside quotes as data, not separators. Naive split-on-comma breaks those rows.

What JSON shape should I use for tables?+

An array of objects — one object per row, keys from headers — is the default for APIs and apps. Use arrays of arrays only when you truly have no headers or need a pure grid.

Is Generatr’s CSV to JSON converter free?+

Yes. It runs in the browser with header detection options, custom delimiters, and preview so you can convert without uploading data to a custom backend account flow.

Ready to try it yourself?

Use the free CSV to JSON Converter — no download, no account.

Launch CSV to JSON Converter