CSV and JSON are the two most common data exchange formats — and both have clear strengths. CSV is compact and human-readable in spreadsheet applications. JSON is the native format for web APIs and JavaScript. Knowing when to use each, and how to convert reliably between them, is a fundamental data skill.
CSV vs JSON — Which to Use When
| CSV | JSON | |
|---|---|---|
| Data structure | Flat rows and columns only | Nested hierarchical data |
| Type support | All values are strings | Numbers, booleans, null, arrays |
| Human editing | Easy in Excel/Sheets | Requires JSON-aware editor |
| API / web use | Less common | Standard format for REST APIs |
| File size (flat data) | More compact | Larger due to repeated keys |
How CSV to JSON Conversion Works
A CSV file has a header row (column names) and data rows. The converter maps each column header to a JSON key and each data row to a JSON object:
CSV input:
name,age,city
Alice,30,London
Bob,25,Manchester
JSON output:
[
{"name": "Alice", "age": 30, "city": "London"},
{"name": "Bob", "age": 25, "city": "Manchester"}
]
The result is a JSON array of objects. Each row becomes one object. If type detection is enabled, numeric values like 30 are output as JSON numbers (not strings); boolean strings like true/false become JSON booleans.
Common Use Cases
- Loading configuration data from a spreadsheet. A product catalogue, price list, or translation file managed in Excel can be exported as CSV and converted to JSON for use in a JavaScript application or API.
- Seeding a database from exported data. Database exports often come as CSV. Convert to JSON to use as seed data with your ORM or database migration tools.
- Feeding data to chart libraries. Most JavaScript chart libraries (Chart.js, D3, Recharts) consume JSON arrays. Export from spreadsheet as CSV, convert to JSON, use directly in your component.
- Mock API responses. Generate realistic mock data in Excel, export to CSV, convert to JSON, and use as fixture data in unit tests or API mocking.
- Preparing data for a REST API request. Some data is provided in CSV format but your API accepts JSON in the request body. Convert and then POST.
Type Detection — Numbers, Booleans, and Nulls
CSV stores everything as text. When converting to JSON, a good converter should detect and convert types:
CSV cell value → JSON type "42" → 42 (number) "3.14" → 3.14 (number) "true" → true (boolean) "false" → false (boolean) "" → null (empty = null, or "") "01234" → "01234" (leading zero → keep as string) "John Smith" → "John Smith" (string)
Caution: Not all converters auto-detect types. Always check the output if your downstream code expects numbers. The CSV to JSON Converter provides type detection options.
Handling Commas Inside CSV Values
name,address,age Alice,"123 High Street, London",30 // Quotes wrap the field containing a comma // Double-quote to escape a literal quote: Bob,"She said ""hello""",25
A proper RFC 4180-compliant CSV parser handles these cases automatically. Never parse CSV with a simple .split(',') — it breaks on comma-containing values.
Nested JSON from Flat CSV
Some converters support "dot notation" column names to produce nested JSON objects:
CSV header: name,address.street,address.city,address.postcode
CSV row: Alice,123 High St,London,SW1A 1AA
Nested JSON output:
{
"name": "Alice",
"address": {
"street": "123 High St",
"city": "London",
"postcode": "SW1A 1AA"
}
}
This is a converter-specific feature, not part of any CSV standard — check whether your tool supports it.