JSON to CSV: Differences, Edge Cases & Pitfalls

Flatten nested JSON into CSV rows with configurable key-path separators and array handling for pivots and bulk imports.

Flattening nested JSON into a table turns key paths into column names. The design decision is what happens to arrays: join into one cell, expand across rows, or emit separate columns. That choice decides whether downstream can pivot and sum, so settle it before converting.

Format Differences

AspectJSONCSV
DepthAnyTwo dimensions only; flattening required
Key setMay differ per objectAll rows share one column set
ArraysNativeExpand into rows, columns, or a joined string
TypesExplicit number/boolean/nullStrings; types live in a convention
Large integersExact as stringsExact as text (downstream parsing may still damage them)
ReadabilityClear structure, machine friendlySpreadsheet friendly, loads into Excel/BI
SizeCompactEven more compact, but repeated headers add redundancy
Best forAPIs, configReports, bulk import, analysis

Edge Cases

  • Values containing commas, newlines or quotes must be quoted with inner quotes doubled, or columns shift.
  • Dotted keys collide with the flattening separator and create ambiguous paths; change the separator or escape.
  • Implementations that take keys from the first object only drop later columns silently — compare column count against the key union.
  • An empty array and a missing key both render blank, so "empty collection" and "no such field" look identical.

Common Pitfalls

  • Emitting a JSON array as a row joins its elements into an unreadable string that cannot be split later.
  • Dotted key names collide with flattened paths so one column name appears twice and lookups hit either at random.
  • Unescaped CJK keys with embedded commas shift the entire header row.
  • Generating columns from the first object alone loses later fields with no warning.

Related Tools