CSV vs JSON: Differences and How to Convert Between Them

Quick answer

CSV is a flat table of rows and columns, ideal for spreadsheets. JSON stores structured, nested data with types, ideal for APIs and apps. To convert CSV to JSON, each row becomes an object keyed by the header row; to convert JSON to CSV, nested objects are flattened into columns like “address.city”.

Side-by-side comparison

CSVJSON
StructureFlat rows and columnsNested objects and arrays
Data typesEverything is textStrings, numbers, booleans, null
Best forSpreadsheets, exports, bulk importsAPIs, configuration, web apps
SizeCompact – headers onceLarger – keys repeat per record
StandardRFC 4180 (loosely followed)RFC 8259 (strict)

Converting CSV to JSON

With a header row, “name,age / Ana,31” becomes [{"name":"Ana","age":31}] when type detection is on. Without it, everything stays a string: "31". Values with leading zeros such as postal codes “01234” should stay strings, otherwise they change meaning.

Convert CSV to JSON

Converting JSON to CSV

Because CSV is flat, nested objects must be flattened. {"user":{"id":1,"city":"Oslo"}} becomes two columns: user.id and user.city. Arrays have no natural column form, so they are usually kept as JSON text inside one cell.

Convert JSON to CSV

Checklist before converting

  • Validate the JSON first – a single trailing comma makes the whole file invalid.
  • Check your CSV delimiter: many European systems use semicolons.
  • Decide how to treat empty cells: empty string or null.
  • Keep IDs longer than 15 digits as text; spreadsheets round them.

Questions and answers

Which is smaller, CSV or JSON?

CSV is usually smaller because column names appear once in the header, while JSON repeats each key in every record.

Can CSV store nested data?

Not natively. Nested values must be flattened into extra columns (such as address.city) or stored as JSON text inside a cell.

Tools used in this guide