CSV to JSON

Convert CSV (comma-separated values) data to JSON array of objects. Supports custom delimiter and headers.

Why convert CSV to JSON?

CSV (Comma-Separated Values) is the universal tabular data format used by Excel, Google Sheets, databases, and data exports. JSON (JavaScript Object Notation) is the universal data format for web APIs, JavaScript apps, NoSQL databases, and modern programming. Converting between them is constantly needed: importing spreadsheet data into web applications, exporting database query results, feeding data to AI/ML pipelines, loading data into JavaScript visualizations, or simply analyzing CSV files with JSON-aware tools. This converter handles complex CSV scenarios: custom delimiters (semicolon for European Excel, tab for TSV), quoted fields with embedded commas, header/no-header rows, and produces clean nested JSON objects with smart key inference from headers.

How to use this tool

  1. Paste CSV input — Tabular data with rows separated by newlines, fields by delimiter.
  2. Choose delimiter — Comma (default, US/UK Excel), Semicolon (European Excel where comma is decimal separator), Tab (TSV files), Pipe (some legacy systems).
  3. Toggle header row — If first row contains column names (recommended). If unchecked, output is array of arrays without keys.
  4. Choose output format — Pretty (2-space indent, readable) or Minified (single line, smaller). Pretty for development, minified for transmission.
  5. Read JSON output — Array of objects with header names as keys, row values as data.

CSV to JSON transformation

Input CSV:

name,age,city
Alice,30,Mumbai
Bob,25,Delhi

Output JSON (with headers):

[
  {
    "name": "Alice",
    "age": "30",
    "city": "Mumbai"
  },
  {
    "name": "Bob",
    "age": "25",
    "city": "Delhi"
  }
]

CSV parsing rules:

  • Fields separated by delimiter (comma/semicolon/tab/pipe)
  • Rows separated by newlines
  • Quoted fields can contain embedded delimiters: “Hello, World”,2024
  • Escape quotes inside quoted fields: “He said “”hi”””
  • Empty fields are valid: ‘Alice,,Mumbai’ has empty middle field

Examples

Excel export → web app: Common workflow – export spreadsheet to CSV, convert to JSON, fetch in JavaScript, display in table.

API consumers: Most modern APIs return JSON. If you receive CSV (legacy systems), convert to JSON for processing.

Data analysis: Python pandas can read both CSV and JSON. Choose JSON if you want nested structure (groups of fields), CSV if flat tabular.

JavaScript visualization libraries: D3.js, Chart.js, Plotly all consume JSON. Convert CSV to JSON before passing to them.

NoSQL database imports: MongoDB, CouchDB, DynamoDB store JSON documents – convert CSV before bulk import.

Tips & best practices

  • Always include header row in your CSV – makes JSON keys meaningful (instead of ‘0’, ‘1’, ‘2’)
  • Use tab delimiter (TSV) for files containing many commas – cleaner than escaped quoted CSVs
  • Excel exports may use semicolon (European) or tab (preferred) – if data is split wrong, change delimiter
  • Quoted strings preserve internal commas: ‘Hello, World’,value (treated as 1 field, not 2)
  • Empty cells become empty strings in JSON output – clean up downstream if needed
  • Number columns stay as strings in JSON – convert in downstream code if you need numeric calculations
  • For very large CSVs (over 50 MB), use a streaming parser library – don’t load entire file in browser memory

Limitations & notes

All CSV values become strings in JSON – no automatic type detection. Numbers, dates, booleans remain quoted. For typed conversion, post-process the JSON. Doesn’t handle multi-line cells within quoted fields perfectly – some edge cases of embedded newlines in CSV may parse incorrectly. For complex nested data, this CSV→JSON gives flat objects only – JSON natively supports nesting that CSV cannot represent.

Frequently Asked Questions

Why are all my numbers strings in the JSON output?

CSV doesn’t distinguish types – everything is text. JSON output preserves this as strings. For typed JSON, post-process to convert: JavaScript: data.map(row => ({…row, age: Number(row.age)})). The tool doesn’t auto-detect types to avoid mistakes (e.g. ZIP codes look like numbers but should stay as strings).

What if my CSV has embedded commas in some fields?

Use quoted fields: “Hello, World” is treated as one field. The tool handles this correctly. If you have many commas in data, consider tab-delimited (TSV) instead – cleaner.

How do I handle different delimiters?

Use the dropdown: Comma (standard US/UK CSV), Semicolon (European Excel because comma is decimal), Tab (TSV – clean for data with commas), Pipe (some legacy systems). If your data looks misaligned, try a different delimiter.

What about CSV files with BOM or special encoding?

The tool reads UTF-8 (most common). BOM (Byte Order Mark) is stripped automatically. If your CSV is in a different encoding (Windows-1252, ISO-8859-1), convert to UTF-8 first using a tool like Notepad++ (Encoding menu).

Can I convert JSON back to CSV?

Yes – use our JSON to CSV tool. Flat JSON (array of objects with same keys) converts cleanly. Nested JSON loses some structure – JSON’s nesting is more expressive than CSV’s flat tabular format.

What if my CSV file is very large (1+ GB)?

Don’t paste 1+ GB into browser – it’ll crash. For massive files, use streaming tools: Python pandas, command-line jq, or specialized ETL pipelines. This browser tool works best for files under 50 MB.

Why does the output show row arrays instead of objects?

If ‘First row’ is set to ‘Data only (no header)’, output is array of arrays. Toggle to ‘Has headers’ to get array of objects with named fields. Best practice: always include a header row in CSV exports.

Related tools

JSON to CSV · JSON Formatter · XML Formatter

Copied to clipboard