Complete JSON-CSV Conversion Guide
Converting between JSON and CSV formats is a common challenge in data work. Whether you need to analyze API response data in Excel, or pass a planner's spreadsheet to your development team — knowing how to convert between these formats efficiently is an essential skill. This guide covers the characteristics of both formats and practical conversion techniques you can apply immediately.
1. JSON vs CSV: Key Differences
Understanding the differences helps you determine which format suits each situation.
JSON (JavaScript Object Notation)
JSON is a versatile data format that supports hierarchical (nested) data structures.
[
{
"id": 1,
"name": "John Smith",
"department": {
"id": 10,
"name": "Engineering"
},
"skills": ["JavaScript", "Python"],
"active": true
}
]
JSON characteristics:
- Supports nested structures (objects within objects, arrays within arrays)
- Multiple data types: strings, numbers, booleans, null, arrays, objects
- Standard format for API communication
- Human-readable structure
CSV (Comma-Separated Values)
CSV is a flat format representing data as rows and columns.
id,name,department,active
1,John Smith,Engineering,true
2,Jane Doe,Planning,false
3,Bob Johnson,Design,true
CSV characteristics:
- Only represents flat 2D table structures
- Fully compatible with Excel and Google Sheets
- Easily parsed by any programming language
- Standard format for database import/export
When to Use Which Format?
| Situation | Recommended Format |
|---|---|
| API development and communication | JSON |
| Excel analysis and reports | CSV |
| NoSQL database | JSON |
| Relational DB import | CSV |
| Complex nested data | JSON |
| Simple tabular data | CSV |
2. JSON → CSV Conversion Guide
There are a few important rules to follow when converting JSON to CSV.
Convertible JSON Structure
Correct format: Array of Objects
[
{"name": "John Smith", "age": 30, "city": "New York"},
{"name": "Jane Doe", "age": 25, "city": "Los Angeles"},
{"name": "Bob Johnson", "age": 28, "city": "Chicago"}
]
This JSON converts to:
name,age,city
John Smith,30,New York
Jane Doe,25,Los Angeles
Bob Johnson,28,Chicago
Key Considerations
1. Flattening Nested Structures
Nested JSON cannot be directly converted to CSV. Flattening is required first.
// Cannot convert: nested structure
[{"user": {"name": "John", "age": 30}, "city": "NYC"}]
// Flatten first, then convert
[{"user_name": "John", "user_age": 30, "city": "NYC"}]
2. Handling Array Fields
// skills is an array → difficult to represent in CSV
[{"name": "John", "skills": ["JS", "Python"]}]
// Solution: join as string or create separate columns
[{"name": "John", "skills": "JS,Python"}]
3. Values Containing Special Characters
Values containing commas, double quotes, or newlines are automatically quoted:
name,address
John Smith,"123 Main St, Suite 456, New York"
Step-by-Step Conversion Process
- Input the entire JSON array (keys from the first object become headers)
- Select delimiter (default: comma)
- Configure header inclusion
- Click the Convert button
- Copy CSV or download as file
3. CSV → JSON Conversion Guide
Convert CSV to JSON when you need to use spreadsheet data in APIs or development.
Basic Conversion Example
Input CSV:
name,age,department,salary
John Smith,30,Engineering,75000
Jane Doe,25,Planning,65000
Bob Johnson,28,Design,70000
Output JSON:
[
{"name": "John Smith", "age": "30", "department": "Engineering", "salary": "75000"},
{"name": "Jane Doe", "age": "25", "department": "Planning", "salary": "65000"},
{"name": "Bob Johnson", "age": "28", "department": "Design", "salary": "70000"}
]
Type Conversion Considerations
When converting from CSV to JSON, all values are strings by default. Additional processing in your application is needed for numeric or boolean types:
// JavaScript type conversion
const data = csvData.map(row => ({
...row,
age: Number(row.age),
salary: Number(row.salary),
active: row.active === 'true'
}))
Header Configuration
- Use first row as header: Standard CSV format — the first row becomes the key names
- No header: All rows treated as data, automatic keys like
field_1,field_2are assigned