CSV to JSON and JSON to CSV

Summary
Definition: CSV stores flat rows of text; JSON stores typed objects and arrays.
Why it matters: Choosing the right format avoids ambiguity and data loss.
Pitfall: CSV cannot directly represent nested or repeated structures.
CSV works well for flat, spreadsheet-style data. JSON is better for structured data.
Converting between them requires clear assumptions about headers, types, and structure.
- CSV
- Text rows and columns separated by delimiters.
- Header
- Row that names columns.
- Flatten
- Convert nested data into flat key paths.
- Schema
- Expected fields and types for data.
- Dialect
- CSV rules such as delimiter and quoting.
- Null
- Explicit missing value in JSON.
How conversion works
CSV to JSON maps each row to an object, usually using headers as keys.
JSON to CSV requires choosing a fixed set of columns and transforming nested data.
Common mix-up: CSV does not store types. Typing must be added during parsing or via metadata.
CSV assumptions and dialects
CSV files vary in delimiter, quoting rules, and header usage.
Most tools assume a header row and comma delimiter, but this is not guaranteed.
Always confirm delimiter, header presence, and encoding before converting CSV.
Handling nulls and empty values
An empty CSV field may mean an empty string or a missing value.
JSON distinguishes these cases with explicit null.
Treat empty values and null consistently or you may introduce silent data errors.
Quick examples
A simple CSV file with a header row.
name,age
Ada,36The same data represented as JSON.
{
"name": "Ada",
"age": 36
}Nested data and arrays
JSON can contain nested objects and arrays that CSV cannot represent directly.
You must choose a transformation strategy before export.
- Flatten nested fields into columns.
- Expand arrays into repeated rows.
- Encode JSON as text in a column (lossy).
There is no single correct CSV to JSON mapping.
Conversions depend on structure, tools, and downstream needs.
Use with Encrypt Online
- Use CSV to JSON for row-to-object conversion.
- Use JSON to CSV for tabular export.
- Use JSON to CSV Flatten for nested data.
Practical check
- Verify delimiter, header row, and encoding.
- Parse numbers, booleans, and dates explicitly.
- Normalize null and empty values.
- Flatten or normalize nested JSON before CSV export.
FAQ
Can CSV represent nested JSON? No. Nested objects and arrays must be flattened or transformed first.
Do CSV values have types? No. CSV values are text; types must be inferred or defined separately.
Are all CSV files the same? No. CSV dialects vary by delimiter, quoting rules, and header usage.