CSV ↔ JSON Converter
Free online tool supporting bidirectional conversion between CSV and JSON formats.
Examples
CSV Example:
name,age,city John,30,New York Jane,25,Los Angeles Bob,35,Chicago
JSON Example:
[
{"name": "John", "age": "30", "city": "New York"},
{"name": "Jane", "age": "25", "city": "Los Angeles"},
{"name": "Bob", "age": "35", "city": "Chicago"}
]Key Features
- Bidirectional Conversion: CSV → JSON, JSON → CSV
- Delimiter Selection: Comma, semicolon, tab, pipe
- Header Option: Use first row as header
- JSON Indentation: 2/4 spaces or compact
- Swap Function: Quickly switch result to input
- Instant Copy: Copy conversion result
What is CSV?
CSV (Comma-Separated Values) is a text format that separates values with commas.
CSV Example
name,age,city
John,30,New York
Jane,25,Los Angeles
Bob,35,Chicago
Characteristics
- Simple and lightweight
- Easy to open in Excel
- Suitable for spreadsheet data exchange
- Cannot represent nested structures
What is JSON?
JSON (JavaScript Object Notation) is a data structure in JavaScript object format.
JSON Example
[
{"name": "John", "age": "30", "city": "New York"},
{"name": "Jane", "age": "25", "city": "Los Angeles"},
{"name": "Bob", "age": "35", "city": "Chicago"}
]
Characteristics
- Structured data representation
- Supports nested structures
- Widely used in web APIs
- Naturally integrates with JavaScript
Conversion Options
Delimiter
| Delimiter | Character | Use Case |
|---|---|---|
| Comma | , | Most common (standard CSV) |
| Semicolon | ; | European (uses comma in numbers) |
| Tab | \t | TSV files, copy/paste |
| Pipe | ` | ` |
Header Row
With Header:
name,age,city
John,30,New York
→
[{"name": "John", "age": "30", "city": "New York"}]
Without Header:
John,30,New York
→
[["John", "30", "New York"]]
Use Cases
1. Excel → JSON
# Copy from Excel
Product,Price,Stock
Apple,1000,50
Banana,500,100
# Convert to JSON
[
{"Product": "Apple", "Price": "1000", "Stock": "50"},
{"Product": "Banana", "Price": "500", "Stock": "100"}
]
2. API Data → CSV
# API response
[
{"id": 1, "name": "Item A", "price": 100},
{"id": 2, "name": "Item B", "price": 200}
]
# Export to CSV
id,name,price
1,Item A,100
2,Item B,200
3. Database Backup
# Save SQL results as CSV
user_id,username,email
1,john_doe,john@example.com
2,jane_smith,jane@example.com
# Convert to JSON and import to NoSQL
4. Configuration File Conversion
# config.json
{
"settings": [
{"key": "theme", "value": "dark"},
{"key": "language", "value": "en"}
]
}
# Export to CSV
key,value
theme,dark
language,en
Programming Examples
JavaScript
// CSV → JSON
const csv = `name,age,city
John,30,New York
Jane,25,Los Angeles`;
const lines = csv.split('\n');
const headers = lines[0].split(',');
const result = [];
for (let i = 1; i < lines.length; i++) {
const obj = {};
const values = lines[i].split(',');
headers.forEach((header, index) => {
obj[header] = values[index];
});
result.push(obj);
}
console.log(JSON.stringify(result, null, 2));
// JSON → CSV
const json = [
{name: 'John', age: 30, city: 'New York'},
{name: 'Jane', age: 25, city: 'Los Angeles'}
];
const headers = Object.keys(json[0]);
const csv = [
headers.join(','),
...json.map(row =>
headers.map(header => row[header]).join(',')
)
].join('\n');
console.log(csv);
Python
import csv
import json
# CSV → JSON
with open('data.csv', 'r') as f:
reader = csv.DictReader(f)
data = list(reader)
with open('data.json', 'w') as f:
json.dump(data, f, indent=2)
# JSON → CSV
with open('data.json', 'r') as f:
data = json.load(f)
with open('data.csv', 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=data[0].keys())
writer.writeheader()
writer.writerows(data)
Limitations
CSV Limitations
- Nested Structure: CSV can only represent flat data
- Data Types: All values treated as strings
- Special Characters: Requires quotes when including commas or line breaks
JSON Limitations
- File Size: Larger capacity than CSV
- Human Readability: Low readability for complex structures
- Excel Compatibility: Cannot be opened directly (conversion needed)
CSV Format Considerations
Quote Handling
# Wrap in quotes if value contains comma
name,description
"Smith, John","Software Developer"
"Doe, Jane","Data Analyst, Manager"
Escaping
# Double quotes inside quotes
name,quote
John,"He said ""Hello"""
Frequently Asked Questions
Q: How are empty values in CSV handled?
A: Converted to empty strings ("") in JSON.
Q: What about nested objects in JSON?
A: This tool only supports flat structures. Nested objects may be converted to strings.
Q: Can it handle large files?
A: Depends on browser memory. Use server-side tools for very large files.
Q: Can I convert Excel files directly?
A: No. First save as CSV in Excel, then use this tool.
🔗 Try These Next
- JSON Formatter - JSON validation and formatting
- Line Numbers - Add line numbers to text
- Text Sorter - Sort text lines