Convert CSV to JSON
How It Works
This converter parses CSV (Comma-Separated Values) data and transforms it into JSON format. It handles:
- Quoted fields: Values containing delimiters or newlines wrapped in quotes
- Escaped quotes: Double quotes inside quoted fields ("")
- Multiple delimiters: Comma, semicolon, tab, pipe, or custom
- Auto-detection: Automatically identifies the delimiter used
Output Formats
Array of Objects (with headers):
[
{ "name": "John", "age": "30" },
{ "name": "Jane", "age": "25" }
]
Array of Arrays:
[ ["name", "age"], ["John", "30"], ["Jane", "25"] ]
Examples
Basic CSV with Headers
Input CSV:
name,email,age Alice,[email protected],28 Bob,[email protected],34
Output (array of objects):
[
{
"name": "Alice",
"email": "[email protected]",
"age": "28"
},
{
"name": "Bob",
"email": "[email protected]",
"age": "34"
}
]
Quoted Fields with Commas
When a value contains the delimiter character, it must be wrapped in double quotes:
company,address,employees Acme Inc,"123 Main St, Suite 4",50 "Smith, Jones & Co","456 Oak Ave",120
The quoted commas are treated as part of the field value, not as delimiters.
Semicolon-Delimited (European Format)
Many European spreadsheet exports use semicolons because commas serve as decimal separators:
product;price;quantity Widget;12,50;100 Gadget;8,99;250
This converter auto-detects the semicolon delimiter and parses correctly.
Tab-Separated Values (TSV)
Database exports and some scientific data use tab characters as delimiters. The auto-detect feature handles this, or select "Tab" from the delimiter dropdown.
CSV vs. JSON — When to Use Each
CSV (Comma-Separated Values) is a flat, tabular text format. Each line is a record, and fields within a line are separated by a delimiter. CSV works well for simple, two-dimensional data — like spreadsheets, data exports, and log files.
JSON (JavaScript Object Notation) is a hierarchical format that supports nested objects, arrays, and typed values (strings, numbers, booleans, null). JSON is the standard for web APIs, configuration files, and NoSQL databases.
| Feature | CSV | JSON |
|---|---|---|
| Structure | Flat (rows and columns) | Hierarchical (nested objects/arrays) |
| Data types | Everything is text | Strings, numbers, booleans, null, arrays, objects |
| File size | Compact for tabular data | More verbose (keys repeated per record) |
| Readability | Good for small tables | Good with formatting |
| Nesting support | None | Unlimited depth |
| Standard | RFC 4180 (loosely followed) | RFC 8259 (strictly followed) |
| Best for | Spreadsheets, bulk data, simple exports | APIs, configs, document stores |
Common CSV Formats by Source
| Source | Typical Delimiter | Encoding | Notes |
|---|---|---|---|
| Excel (US/UK) | Comma | UTF-8 or Windows-1252 | Default export; may include BOM |
| Excel (Europe) | Semicolon | UTF-8 or Windows-1252 | Comma used as decimal separator in locale |
| Google Sheets | Comma | UTF-8 | Clean UTF-8 export; most reliable |
| PostgreSQL COPY | Tab | UTF-8 | Default delimiter for COPY TO |
| MySQL SELECT INTO | Tab | UTF-8 | Default for SELECT INTO OUTFILE |
| AWS Athena / Redshift | Comma or Pipe | UTF-8 | Pipe avoids conflicts with data |
| R / Python pandas | Comma | UTF-8 | Standard write.csv() / to_csv() |
Common Use Cases
- REST API payloads: APIs expect JSON request bodies. Convert spreadsheet data to JSON before sending POST/PUT requests.
- MongoDB imports: Import spreadsheet data into MongoDB. Convert CSV to a JSON array of objects, then use
mongoimport --jsonArray. - JavaScript applications: Load tabular data into a web app. JSON is natively parsed by
JSON.parse()— no CSV parser library needed. - Configuration generation: Turn a spreadsheet of settings, feature flags, or translations into structured JSON config files.
- Data migration: Move data between systems that use different formats. CSV is the universal export format; JSON is the universal API format.
- Testing and prototyping: Quickly generate test data from a spreadsheet for use in API testing tools like Postman or Insomnia.
- Static site data: Convert a spreadsheet of products, team members, or FAQs into JSON for use in static site generators (Eleventy, Gatsby, Hugo).
Common Mistakes When Converting CSV to JSON
- Assuming all values are numbers: CSV has no data types. The value "007" is a string, not the number 7. If you auto-convert to numbers, you may lose leading zeros (zip codes, product IDs).
- Ignoring quoted fields: A naive split on commas will break fields that contain commas inside quotes. Always use a proper CSV parser that handles RFC 4180 quoting.
- Wrong delimiter: European CSV files often use semicolons, not commas. If your JSON has a single key per row containing commas, the delimiter is probably wrong.
- Encoding issues: Excel on Windows may export as Windows-1252, not UTF-8. Characters like é, ü, or — may appear garbled. Re-save as UTF-8 or use an encoding-aware tool.
- Empty trailing columns: Some exports include trailing delimiters, creating empty fields at the end of each row. Trim these before converting.
- Missing headers: If you enable "first row is headers" but the first row is data, you'll lose a row. If you disable it but the first row is headers, you'll get headers as a data row.
- Newlines inside fields: Some CSV fields contain line breaks (e.g., address fields). These must be quoted. A simple line-by-line parser will break — use a proper RFC 4180-compliant parser.
How to Convert CSV to JSON from the Command Line
For automation, scripting, or large files, command-line tools are faster than browser-based converters:
Python (built-in, no install needed)
python3 -c "
import csv, json, sys
reader = csv.DictReader(sys.stdin)
print(json.dumps(list(reader), indent=2))
" < data.csv > data.json
Miller (mlr) — purpose-built for data format conversion
mlr --icsv --ojson cat data.csv > data.json
Node.js (one-liner)
node -e "
var lines = require('fs').readFileSync('/dev/stdin','utf8').trim().split('\n');
var headers = lines[0].split(',');
var data = lines.slice(1).map(r => {
var vals = r.split(',');
return Object.fromEntries(headers.map((h,i) => [h, vals[i]]));
});
console.log(JSON.stringify(data, null, 2));
" < data.csv
Note: The Node.js one-liner uses a simple comma split. For CSV with quoted fields, use a library like csv-parse or papaparse.
Frequently Asked Questions
How do I convert CSV to JSON?
Paste your CSV data into a converter, select whether the first row contains headers, and choose your output format. The converter maps each row to a JSON object using header values as keys. You can also convert from the command line using Python, Miller, or Node.js.
What is the difference between CSV and JSON?
CSV is a flat, tabular text format — rows and columns, like a spreadsheet. JSON is a hierarchical format that supports nested objects, arrays, and typed values. CSV is simpler and more compact for flat data. JSON is more flexible and the standard format for web APIs and modern applications.
Why would I convert CSV to JSON?
Common reasons: sending data to a REST API that expects JSON, importing spreadsheet data into MongoDB or another NoSQL database, loading data into a JavaScript application, generating configuration files, and data migration between systems.
What delimiters are supported?
This converter supports comma (,), semicolon (;), tab, and pipe (|) delimiters, plus any custom character. Auto-detection analyzes the first few rows for consistency. European CSV exports commonly use semicolons because commas serve as decimal separators.
How are quoted fields handled?
Fields containing delimiters, newlines, or quotes are enclosed in double quotes per RFC 4180. A literal double quote inside a quoted field is escaped by doubling it: "". For example, "Smith, Jr." is parsed as a single field containing Smith, Jr.
What is the difference between array of objects and array of arrays?
Array of objects uses header values as keys: [{"name": "Alice", "age": "28"}]. Array of arrays keeps positional data: [["name", "age"], ["Alice", "28"]]. Objects are most common for APIs and databases. Arrays are useful for data without headers or when column order matters.
Why are all my values strings instead of numbers?
CSV is a plain text format with no data types — every value is a string. This converter preserves that behavior. If you need typed values, post-process the JSON: use parseFloat() or Number() for numbers, and value === "true" for booleans.
Can this handle large CSV files?
This browser-based converter handles files up to several megabytes. For larger files (100 MB+), use command-line tools like Python's csv module, Miller (mlr), or stream-based parsers that don't load everything into memory at once.
What is RFC 4180?
RFC 4180 defines the CSV format: fields separated by commas, records separated by CRLF line breaks, quoted fields for values containing commas or quotes, and doubled double-quotes for escaping. It's the closest thing to a CSV standard, though many real-world files don't follow it strictly.
How do I convert CSV to JSON from the command line?
The most portable method is Python: python3 -c "import csv,json,sys; print(json.dumps(list(csv.DictReader(sys.stdin)),indent=2))" < file.csv. For a dedicated tool, Miller (mlr --icsv --ojson cat file.csv) is fast and handles edge cases well.
Can I convert JSON back to CSV?
Yes — use our JSON to CSV converter. The reverse conversion flattens JSON objects into rows and columns. Nested JSON must be flattened first, which requires decisions about how to represent nested keys as column names.
Does this tool send my data to a server?
No. All parsing and conversion runs entirely in your browser using JavaScript. Your CSV data never leaves your device. Nothing is stored, transmitted, or logged.
Related Tools
- JSON to CSV Converter — convert JSON arrays back to CSV format
- CSV Delimiter Converter — switch between comma, semicolon, tab, and pipe delimiters
- JSON Formatter — format, beautify, and validate JSON
- JSON Validator — check JSON syntax with detailed error messages
- CSV ↔ JSON Converter — two-way conversion between CSV and JSON
- CSV to JSON Conversion Guide — in-depth guide to converting between CSV and JSON
Privacy & Limitations
- Client-side only. No data is sent to any server. No cookies, no tracking of pasted content.
- RFC 4180 parsing. Handles quoted fields, escaped quotes, and mixed line endings. Does not handle all non-standard CSV variants (e.g., backslash escaping).
- No type inference. All values are output as JSON strings. Numeric or boolean conversion must be done separately.
- Size limits. Browser-based processing works well for files up to a few megabytes. For very large CSV files, use a command-line tool.
Related Tools
View all toolsBig-O Notation Visualizer
Interactive plot of O(1) through O(n!) complexity curves with operation count comparison
JSON Formatter
Format and beautify JSON with proper indentation
JSON Validator
Validate JSON syntax and show errors
JSON to CSV Converter
Convert JSON arrays to CSV format with nested object handling
JWT Decoder
Decode JWT tokens and display header and payload
Hash Generator
Generate MD5, SHA-1, SHA-256, SHA-512 hashes
CSV to JSON Converter FAQ
How do I convert CSV to JSON?
Paste your CSV data into a converter tool, select whether the first row contains headers, and choose your output format. The converter parses each row and maps columns to JSON keys (from the header row) or array indices. Online tools, command-line utilities like jq and Python, and programming libraries all support this conversion.
What is the difference between CSV and JSON?
CSV (Comma-Separated Values) is a flat, tabular text format — rows and columns, like a spreadsheet. JSON (JavaScript Object Notation) is a hierarchical format that supports nested objects, arrays, and typed values (strings, numbers, booleans, null). CSV is simpler but cannot represent nested data. JSON is more flexible but more verbose for flat tables.
Why would I convert CSV to JSON?
Common reasons include: feeding data into a REST API that expects JSON, importing spreadsheet data into a NoSQL database like MongoDB, using data in JavaScript applications, creating configuration files, and processing data with tools that work better with structured JSON than flat CSV.
What delimiters does this CSV converter support?
This converter supports comma (,), semicolon (;), tab, and pipe (|) delimiters, plus any custom single character. It auto-detects the delimiter by analyzing the first few rows for consistency. European CSV exports commonly use semicolons because commas serve as decimal separators in those locales.
How are quoted fields handled in CSV?
Fields containing delimiters, newlines, or quotes are enclosed in double quotes. A literal double quote inside a quoted field is escaped by doubling it. For example, the CSV value '"Smith, Jr."' contains a comma but is treated as a single field. This converter follows RFC 4180 quoting rules.
What is the difference between array of objects and array of arrays output?
Array of objects uses the header row as keys: [{"name": "Alice", "age": 30}]. Array of arrays keeps raw row data: [["name", "age"], ["Alice", "30"]]. Use objects when you need named fields (most common for APIs and databases). Use arrays when you need positional data or have no headers.
Does this tool handle large CSV files?
This browser-based converter handles files up to several megabytes comfortably. For very large files (100 MB+), use command-line tools like Python (csv and json modules), jq, or Miller (mlr). These process data as streams without loading everything into memory.
Why are all my JSON values strings instead of numbers?
CSV is a plain text format with no data types — every value is a string. Most simple converters preserve this. If you need typed values (numbers, booleans), you need to post-process the JSON or use a converter with type inference. In JavaScript, you can use parseFloat() or JSON.parse() on individual values.
How do I convert CSV to JSON from the command line?
With Python: python -c "import csv,json,sys; r=csv.DictReader(sys.stdin); print(json.dumps(list(r),indent=2))" < file.csv. With Miller (mlr): mlr --icsv --ojson cat file.csv. With jq and Miller combined for complex transformations. Python's approach is the most portable since it requires no extra installation.
What is RFC 4180?
RFC 4180 is the specification that defines the CSV format. Key rules: fields are separated by commas, records are separated by line breaks (CRLF), fields containing commas or quotes must be enclosed in double quotes, and double quotes inside fields are escaped by doubling them. Not all CSV files follow RFC 4180 strictly, which is why delimiter auto-detection is useful.
Is my data sent to a server?
No. All parsing and conversion happens in your browser using JavaScript. Your CSV data never leaves your device. Nothing is stored, transmitted, or logged. You can verify this by disconnecting from the internet — the tool works identically offline.
Can I convert JSON back to CSV?
Yes. The reverse conversion (JSON to CSV) flattens JSON objects into rows and columns. You can use our JSON to CSV converter tool for this. Note that nested JSON structures need to be flattened first, which may require decisions about how to represent nested keys as column names.