How to Convert CSV to JSON (and Back) Instantly

2026-03-10 3 min read
csvjsondataconversion

CSV and JSON are two of the most common data formats you’ll encounter. Knowing how to convert between them — and when each format makes sense — is a useful skill for developers, data analysts, and anyone who works with data.

CSV: simple and tabular

CSV (Comma-Separated Values) is plain text where each line is a row and values are separated by commas:

name,age,city
Alice,30,New York
Bob,25,London
Carol,35,Tokyo

Strengths: Human-readable, tiny file sizes, opens in any spreadsheet app (Excel, Google Sheets), easy to edit manually.

Weaknesses: No nested data, no data types (everything is a string), delimiter conflicts (what if a value contains a comma?).

JSON: structured and flexible

JSON (JavaScript Object Notation) represents the same data with explicit structure:

[
  { "name": "Alice", "age": 30, "city": "New York" },
  { "name": "Bob", "age": 25, "city": "London" },
  { "name": "Carol", "age": 35, "city": "Tokyo" }
]

Strengths: Supports nested objects and arrays, preserves data types (numbers, booleans, null), native to JavaScript and most APIs.

Weaknesses: Larger file sizes, harder to edit in a spreadsheet, more verbose.

When to use which

ScenarioUse
Spreadsheet import/exportCSV
API request/responseJSON
Database export for analysisCSV
Configuration filesJSON
Simple flat dataCSV
Nested or complex dataJSON
Sharing with non-technical usersCSV

Converting CSV to JSON

The conversion process:

  1. Parse the header row — The first line defines the field names
  2. Parse each data row — Split by delimiter (comma, tab, semicolon, etc.)
  3. Build objects — Map each value to its corresponding header
  4. Handle edge cases — Quoted values, escaped delimiters, empty fields

Watch out for:

  • Delimiter conflicts — Values containing commas should be wrapped in quotes
  • Line breaks in values — Quoted fields can contain newlines
  • Encoding — UTF-8 is standard, but some files use other encodings
  • Empty values — Decide whether they should be empty strings, null, or omitted

Converting JSON to CSV

Going the other direction:

  1. Extract keys — Use the keys from the first object as column headers
  2. Flatten nested data — Nested objects need to be flattened or stringified
  3. Escape special characters — Wrap values containing delimiters in quotes
  4. Write rows — Output each object as a comma-separated line

Common pitfalls:

  • Nested objects — CSV is flat, so { address: { city: "NYC" } } needs to become address.city or be serialized
  • Arrays in values — No standard way to represent arrays in CSV
  • Inconsistent keys — If objects have different keys, you need to handle missing values

Custom delimiters

Not all “CSV” files use commas. Common alternatives:

  • Tab (TSV) — Common in database exports
  • Semicolon — Standard in European locales where comma is the decimal separator
  • Pipe (|) — Used when data contains commas and semicolons

When converting, make sure to detect or specify the correct delimiter.

Browser-based conversion

For quick conversions, browser-based tools are the fastest option. Paste your CSV or JSON, and get the converted output instantly. No uploading, no installing, no waiting. The conversion happens entirely in your browser using JavaScript.

Try it yourself

Use the tool mentioned in this article — free, no sign-up, runs in your browser.

Open Tool