AI Tools Free
Data & File Conversion Guides

How to Flatten and Convert JSON to CSV (Plus When to Switch from CSV to Parquet)

Flatten nested JSON objects and arrays into clean CSV tables, fix UTF-8 BOM encoding issues in Excel, and compare CSV vs. Apache Parquet file sizes.

Interactive tool JSON to CSV Converter
JSON to CSV Converter Open Free Tool

Exporting an API response to CSV works smoothly until the JSON payload contains a nested object or an array of tags. Naive scripts either crash, dump literal [object Object] strings into spreadsheet cells, or misalign columns whenever an optional field is missing on the first record.

Converting hierarchical JSON into a flat 2D table requires three rules: unioning keys across all rows, flattening nested objects with dot notation, and escaping embedded commas and newlines according to RFC 4180.

Why Nested JSON Objects Break Standard CSV Exports (And How Flattening Works)

Consider a two-record API response where the second item includes an optional shipping.tracking key that the first item omits:

[
  {
    "order_id": 1042,
    "customer": { "name": "Elena Rostova", "tier": "pro" },
    "tags": ["priority", "eu-west"]
  },
  {
    "order_id": 1043,
    "customer": { "name": "Marcus Vance", "tier": "free" },
    "shipping": { "tracking": "1Z999AA101" },
    "tags": []
  }
]

If a converter inspects only records[0] to build the CSV header row, shipping.tracking is silently dropped from the entire file. A proper flattening pass scans all objects first to build the complete header union, joins nested object keys with dots (customer.name, customer.tier, shipping.tracking), and serializes arrays as pipe-delimited or JSON-encoded strings:

order_id,customer.name,customer.tier,shipping.tracking,tags
1042,Elena Rostova,pro,,"priority|eu-west"
1043,Marcus Vance,free,1Z999AA101,""

Before flattening a raw webhook or REST payload, validate its syntax and inspect the nesting depth in the JSON Formatter, then convert it directly in your browser.

If you are moving in the opposite direction and need to turn a flat spreadsheet export back into structured JSON objects for an API import or test fixture, use the reverse converter.

Fixing Broken CSV Files in Excel: UTF-8 BOM, Leading Zeros, and RFC 4180 Escaping

Even a well-formed CSV file can break when opened in Microsoft Excel if you overlook three formatting details:

RFC 4180 Quoting Rule: Any field containing a delimiter (,), a line break (\r\n or \n), or a double quote (") must be enclosed in double quotes, and any literal double quote inside the field must be doubled ("").

  1. Garbled non-ASCII characters (é instead of é): When you double-click a UTF-8 .csv file on Windows, older Excel builds assume Windows-1252 unless the file starts with a 3-byte UTF-8 Byte Order Mark (EF BB BF).
  2. Ragged column counts: A single unescaped comma inside a product description shifts every subsequent column one cell to the right for that row. Run the file through a structural validator to catch rows whose column count doesn't match the header.

CSV vs. Parquet: File Size, Schema Preservation, and Query Speed

CSV is ideal for human inspection and files under 50,000 rows. Once a dataset grows past 100 MB or enters an analytics pipeline (DuckDB, BigQuery, Spark, Pandas, or Polars), CSV becomes a bottleneck because it is row-oriented and untyped: every query has to parse every byte of every row as text and guess whether 0042 is an integer or a string.

Apache Parquet stores data in compressed column chunks with an embedded binary schema.

FeatureCSV (Row-Oriented Text)Apache Parquet (Columnar Binary)
Storage LayoutRow by row (r1c1, r1c2, r1c3...)Column by column (all values of col1 stored together)
Data Types (int64, timestamp, bool)Lost (everything is plain text; must be re-parsed on read)Strictly preserved in the file footer metadata
Typical File Size (1M rows, 12 columns)~145 MB uncompressed~18 MB to 26 MB (80%+ reduction via dictionary + RLE + Snappy/Zstd)
SELECT AVG(price) Scan CostReads 100% of the file from diskReads only the price column chunk (<10% of file bytes)
Human Readable in a Text Editor?YesNo (requires Parquet viewer, DuckDB, or Python/JS reader)

My recommendation: keep CSV for exports under 10 MB that non-technical teammates will open in Excel or Google Sheets. Switch to Parquet as soon as the file feeds automated scripts, BI dashboards, or repeated SQL queries, or whenever preserving exact integer, decimal, and timestamp types matters.

Frequently asked questions

Why does my JSON to CSV export show [object Object] in spreadsheet columns?

Basic converters only read top-level key-value pairs and call .toString() on nested objects, which outputs [object Object] in JavaScript. Use a converter that flattens nested keys using dot notation (such as customer.address.postalCode) before generating CSV rows.

How do I stop Excel from stripping leading zeros from ZIP codes and SKU numbers in CSV files?

Excel automatically parses unquoted numeric strings as numbers, turning 07030 into 7030. Instead of double-clicking the CSV file, open Excel and use Data -> From Text/CSV, then set the column data type to Text, or store the dataset in a typed format like Apache Parquet.

How much smaller is a Parquet file compared to the same CSV file?

On typical analytical datasets with mixed strings, timestamps, and numbers, Apache Parquet with Snappy or Zstandard compression is 70% to 85% smaller than raw CSV because it stores data by column and applies dictionary and run-length encoding.