Flat JSON Objects to CSV

Convert flat JSON objects with consistent keys to CSV. The simplest JSON-to-CSV case with direct key-to-column mapping and no flattening required.

Advanced Conversion

Detailed Explanation

Flat JSON to CSV Conversion

When your JSON array contains flat objects (no nesting, no arrays as values), the conversion to CSV is straightforward and loss-free. Each key becomes a column header, and each value becomes a cell.

Input JSON

[
  { "sku": "A001", "name": "Laptop Stand", "price": 29.99, "qty": 150 },
  { "sku": "A002", "name": "USB-C Hub", "price": 49.99, "qty": 75 },
  { "sku": "A003", "name": "Monitor Light", "price": 39.99, "qty": 200 }
]

Output CSV

sku,name,price,qty
A001,Laptop Stand,29.99,150
A002,USB-C Hub,49.99,75
A003,Monitor Light,39.99,200

Why flat JSON is the ideal case

  • 1:1 mapping. Every JSON key maps directly to a CSV column. No flattening, expansion, or stringification is needed.
  • Type preservation. Numbers and booleans convert to their string representation in CSV. Since CSV readers typically auto-detect types, round-tripping is seamless for simple data.
  • Column order. Modern JavaScript engines preserve object insertion order, so Object.keys() returns keys in a predictable sequence. However, if objects were created differently, key order may vary. To guarantee consistent columns, sort the headers alphabetically or use a predefined order.

Handling inconsistent objects

Real-world JSON arrays may have objects with different sets of keys:

[
  { "sku": "A001", "name": "Laptop Stand", "price": 29.99 },
  { "sku": "A002", "name": "USB-C Hub", "qty": 75 }
]

The correct approach is to compute the union of all keys across all objects and fill missing values with empty cells:

sku,name,price,qty
A001,Laptop Stand,29.99,
A002,USB-C Hub,,75

Performance note

For flat JSON with uniform keys, conversion is O(n * k) where n is the number of objects and k is the number of keys. This is the fastest CSV conversion case because no recursive traversal is needed. Even arrays with millions of rows convert in seconds in a browser using streaming or chunked processing.

Use Case

Exporting a product inventory from a REST API into a CSV file for bulk upload to an e-commerce platform like Shopify or Amazon Seller Central.

Try It — CSV ↔ JSON Converter

Open full tool