Advertisement
📊

CSV to JSON Converter

Convert CSV (comma-separated values) to clean, valid JSON in your browser. Handles quoted fields, embedded commas and newlines, custom delimiters, and outputs an array of objects or a 2D array. 100% client-side — files never leave your device.

Advertisement

Convert CSV to JSON the Right Way

CSV looks deceptively simple — values separated by commas, rows separated by newlines — but real-world CSV files are riddled with edge cases: quoted fields containing commas, escaped quotes, embedded newlines, BOMs from Excel, semicolons in European locales, and the occasional rogue line ending. A naive line.split(',') breaks on all of these. This converter implements a proper RFC 4180 parser that handles them correctly, then renders the result as clean, valid JSON.

How the Parser Handles Edge Cases

  • Quoted fields with commas"Doe, John",42 is parsed as two fields: Doe, John and 42. Commas inside quotes are not delimiters.
  • Escaped quotes — Two double-quotes inside a quoted field represent one literal double-quote. "He said ""hi""." becomes He said "hi".
  • Embedded newlines — A newline inside a quoted field is preserved, not treated as row terminator. Useful for address fields, multi-line comments, and long-form text.
  • UTF-8 BOM — Excel and some other tools prepend three magic bytes (EF BB BF) to UTF-8 files. The parser strips this automatically so it doesn't end up as part of the first column name.
  • Trailing newline — Most CSV exports end with a newline. The parser ignores empty trailing rows so your JSON doesn't get a phantom null entry at the end.
  • Mixed line endings\r\n (Windows), \n (Unix), and \r (legacy Mac) are all handled.

Choosing the Output Format

Array of objects uses the first row as keys, producing one object per data row:

// Input:
// name,age,city
// Alice,30,Paris
// Bob,25,Berlin

[
  { "name": "Alice", "age": "30", "city": "Paris" },
  { "name": "Bob",   "age": "25", "city": "Berlin" }
]

This is the format you'll feed into JSON.parse and iterate with .map() in JavaScript, or load into a Pandas DataFrame in Python. Use it whenever the CSV has a meaningful header row.

2D array preserves the raw row-and-column structure with no header inference:

[
  ["name", "age", "city"],
  ["Alice", "30", "Paris"],
  ["Bob",   "25", "Berlin"]
]

Use this when you don't trust that the first row is a header, when columns have duplicate names (which break the object form), or when you need positional access in code that doesn't care about column names.

Type Coercion: When to Enable It

By default, every value in the output is a string — even numeric-looking ones like 42. This is intentional. CSV has no type system, and any code that auto-converts can corrupt your data. The classic example: a column of US ZIP codes containing 02134 gets silently converted to the integer 2134, dropping the leading zero. The same problem hits product SKUs, ISBNs, and phone numbers.

Enable Coerce types only when you've confirmed the data is numeric/boolean by nature: financial reports, scientific measurements, sensor readings. The coercion rules are:

  • Strings matching /^-?\d+$/ become integers
  • Strings matching /^-?\d*\.\d+$/ become floats
  • Exact true / false (case-insensitive) become booleans
  • Empty strings become null
  • Everything else stays a string

If you need to preserve string fidelity but also want types for some columns, do the coercion in code after parsing — it gives you per-column control.

Doing the Same in Code

// Node.js — using csv-parse for streaming
import { parse } from 'csv-parse/sync';
const records = parse(csvString, {
  columns: true,        // array of objects with header keys
  skip_empty_lines: true,
  cast: false           // keep strings; turn on for numeric columns
});

// Python — using csv.DictReader
import csv, json
with open('data.csv', encoding='utf-8-sig') as f:  // utf-8-sig strips BOM
    rows = list(csv.DictReader(f))
print(json.dumps(rows, indent=2))

// Python — using pandas (best for large files)
import pandas as pd
df = pd.read_csv('data.csv', dtype=str)             // dtype=str disables coercion
print(df.to_json(orient='records', indent=2))

For very large files (50 MB+) prefer streaming parsers like csv-parse in Node, pandas.read_csv(chunksize=10000) in Python, or the csv command-line tool. This browser-based converter is great for ad-hoc work; it's not suited for multi-gigabyte ETL.

Common Pitfalls and Fixes

  • European-locale CSV uses semicolons, not commas — because the comma is the decimal separator. Switch the Delimiter to ; or use Auto-detect.
  • Excel exports as ANSI / Windows-1252 by default — special characters (é, ñ, €) become mojibake. Save as CSV UTF-8 in Excel's Save As dialog.
  • Tab-separated values (TSV) are the same idea with \t as delimiter — pick Tab in the dropdown. TSV avoids most quoting issues since tabs rarely appear inside fields.
  • Pipe-delimited (PSV) is common in older mainframe exports. Pick Pipe.
  • Duplicate column names (e.g., two columns both called Email) break the object form — only the last one wins. Switch to 2D array or rename the columns.

Need to go the other way? Use the JSON to CSV tool (under Related Tools). For ad-hoc filtering, sorting, or aggregating before conversion, our JSON Formatter is the next step.

How to Use

  1. Paste your CSV into the input box, or click one of the sample buttons to see how the parser handles a particular pattern.
  2. Pick the right delimiter — comma, semicolon, tab, or pipe. Use Auto-detect if you're not sure.
  3. Choose the output shape — array of objects (with header keys) or 2D array (raw rows).
  4. Toggle 'Coerce types' only if you want strings like 42 and true converted to numbers and booleans. Leave off to preserve leading zeros and ID strings.
  5. Click Convert — the JSON appears in the output box. Use Copy to grab it, Download to save it as a .json file.

Frequently Asked Questions

Does this tool send my CSV data anywhere?

No. Parsing and conversion happen entirely in JavaScript inside your browser tab — there is no upload, no fetch(), and no analytics ping that includes your data. You can verify this by opening DevTools → Network and watching: pasting and clicking Convert produces no network traffic. Safe for sensitive data.

How are quoted fields and embedded commas handled?

Per RFC 4180, fields containing the delimiter, double quotes, or newlines must be wrapped in double quotes, and any literal double quote inside the field is escaped as two double quotes (""). The parser handles this correctly: a row like `"Doe, John",42,"New York"` becomes three fields. Multi-line fields (newlines inside quotes) are also preserved.

Can I use a different delimiter (semicolon, tab, pipe)?

Yes. The Delimiter dropdown supports comma, semicolon (common in European exports), tab (TSV), and pipe. You can also enter a custom single character. The tool auto-detects delimiter on the first non-quoted line if you choose Auto.

What's the difference between 'array of objects' and '2D array' output?

Array of objects uses the first row as keys: `[{"name":"Alice","age":"30"}, {"name":"Bob","age":"25"}]` — best when the CSV has a header row and you want named access. 2D array preserves the raw row structure: `[["Alice","30"], ["Bob","25"]]` — best when you don't want to assume a header row, or you need positional access.

Are numeric and boolean values converted, or kept as strings?

By default everything is a string — CSV has no native types, and converting eagerly can break IDs that look like numbers ("00123" → 123 loses leading zeros). Toggle the 'Coerce numbers and booleans' option to convert: "42" → 42, "3.14" → 3.14, "true"/"false" → boolean, empty cells → null. The original string form is always available if you re-run with the toggle off.

Why does my Excel CSV have weird characters at the start?

Excel writes a UTF-8 BOM (byte-order mark — three bytes EF BB BF) at the start of the file. The tool strips it automatically before parsing, so you should not see it in the output. If you do, paste the file content again — sometimes the BOM is mid-paste due to clipboard behavior.

Is there a row or file size limit?

The tool can handle several MB of CSV with thousands of rows in your browser. For very large files (50MB+) consider a streaming parser like Node.js's csv-parse or Python's pandas/csv module. The output preview is truncated at 5MB to keep the page responsive — use Copy or Download to get the full result.

Can I convert JSON back to CSV?

Yes — use the JSON to CSV tool (linked under Related Tools). Round-tripping CSV → JSON → CSV with the same options will preserve data, though field order in objects may follow the first row's column order rather than the original CSV column order.

Comments

No comments yet. Be the first!