Skip to content
Tool4SaaS
ToolsGuidesAboutContact
Tool4SaaS

125 fast, local utilities for developers and creators. No sign-ups — most tools run in your browser.

hello@tool4saas.com

Languages:

English

Español

Français

Categories

  • Text & Documents

  • Business & Writing

  • Developer Tools

  • Converters

  • Generators

  • Images & Design

  • PDF Tools

  • Calculators

  • Finance & Money

  • Health & Fitness

  • SEO & Marketing

  • Time & Date

Popular tools

  • Invoice Generator

  • QR Code Generator

  • Word Counter

  • JSON Formatter

  • Mortgage Calculator

  • Resume Builder

  • View all tools →

Learn

  • All Guides & Tutorials

  • Word Counter Guide

  • Invoice Generator Guide

  • QR Code Generator Guide

  • Resume Builder Guide

  • About Us

  • Author

  • Methodology

  • Contact Us

© 2026 Tool4SaaS. All rights reserved.

  • Privacy Policy

  • ·
  • Terms of Service

  • ·
  • ·
  • ·
  • llms.txt

  1. Home
  2. /
  3. Blog
  4. /
  5. Developer Guide
  6. /
  7. JSON to CSV: Convert Flat Arrays Correctly

JSON to CSV: Convert Flat Arrays Correctly

Convert a flat JSON array to CSV correctly: union keys, leave missing values blank, escape commas and quotes, and know when to flatten nested data first.

By Tool4SaaS Editorial Team · Published October 23, 2026 · Updated October 23, 2026 · 6 min read

Try it now — JSON ↔ CSV Converter, free in your browser

Convert between JSON and CSV · No signup · No watermark · Free forever.

Open JSON ↔ CSV Converter →
On this page
  • The flat array rule
  • Union keys and order
  • Escaping cells
  • Nested JSON
  • Reverse direction and limits
  • Conversion workflow

A spreadsheet request sounds simple: take the JSON returned by an API and turn it into rows. The first attempt often produces a single column of [object Object], or columns that shift when one record carries an extra field. JSON and CSV disagree about structure. JSON allows nested objects and missing keys; CSV expects a rectangle of cells. Conversion works when the source is a flat array of objects and you understand how the converter builds the header, fills gaps and escapes values.

Part of the developer toolkit guide. Run the conversion in the JSON to CSV converter. If the payload needs repair first, the JSON parse error guide covers the common syntax faults.

The flat array rule

The converter accepts one shape: a JSON array whose entries are objects. A top-level object fails with “JSON must be an array of objects.” An array of strings or numbers has no stable field names, and a null entry has no keys, so neither belongs in a CSV export. Wrap each record in an object with named properties before converting.

Flat means each value is a scalar: a string, number, boolean or null. Nested objects are not flattened. The converter calls String(value), so {"customer":{"name":"Ada"}} becomes [object Object] in the cell. Arrays are turned into comma-joined text, which can collide with the CSV delimiter. If a cell must hold a list, serialize it deliberately first, for example as math|science.

An empty array returns empty output, not a header, because there are no keys to union. A single object outside an array is rejected even though it looks like one record. If the API wraps the rows in a field such as data or results, unwrap that field first; the converter does not search inside an object for the first array it finds. These strict shapes are deliberate: guessing where the rows live would create silent, hard-to-audit exports.

The tool also has no delimiter menu. Output is comma-separated. If a locale expects semicolons, do not assume conversion will adapt; convert first, then handle the separator in your spreadsheet import step. The header is built from JSON keys, not from a template you supply.

Union keys and column order

The header is the union of every key in the array, in first-seen order. It is not taken from the first row alone. A field that appears only in the third record still becomes a column, placed after the keys seen earlier. Records without that key get an empty cell. This design prevents data loss, but it also means the column order depends on the order of the source array.

Example 1 shows the effect. The input is [{"id":1,"name":"Ada","team":"math"},{"id":2,"name":"Grace","email":"g@example.com"},{"id":3,"name":"Linus","team":"kernel","active":true}]. The output header is id,name,team,email,active. Ada has no email or active value, Grace has no team or active value, and Linus has no email. The rows are still aligned because every row is written against the same header.

This is why a single sample record is a poor template. Before exporting, scan the whole array for the largest set of keys. If Excel must see a fixed order, normalize the objects in the source, or reorder the CSV columns after conversion. The tool does not alphabetize or let you drag columns.

Escaping commas, quotes and newlines

Simple values pass through unchanged. Any value containing a comma, double quote or newline is wrapped in double quotes, and internal quotes are doubled. That is standard CSV, and it is the reason a cell can contain punctuation without splitting the row. The table shows the behavior you should expect.

Value in JSONCell in CSVRule
AdaAdaNo special characters, no wrapping
Ada, Jr."Ada, Jr."Comma forces quotes
She said "hi""She said ""hi"""Quotes are doubled inside a quoted cell
Line one
Line two
"Line one
Line two"
Newline stays inside one quoted cell
null(empty)Null and missing values become blanks
truetrueBooleans are written as text
{"a":1}[object Object]Nested objects are not flattened

One limit sits outside the cell rules: header names are joined directly and are not escaped. A key containing a comma, quote or newline can break the header row. Rename such keys before conversion. Long numeric IDs are another quiet problem, because JSON.parse rounds integers beyond its safe range; store identifiers as strings when precision matters.

Nested JSON: flatten before converting

Example 2 is a typical order record: [{"order":1001,"customer":{"name":"Ada","city":"London"},"items":[{"sku":"A1","qty":2}],"total":49.5}]. The converter produces a header of order,customer,items,total and a row where both customer and items read [object Object]. The numbers survive; the structure does not. That output is not a bug in the escaping, it is the flat-array rule meeting data that is not flat.

Flatten the record before conversion. A workable line-item table is [{"order":1001,"customer_name":"Ada","customer_city":"London","item_sku":"A1","item_qty":2,"total":49.5}]. If an order has several items, emit one row per item and repeat the order fields, which is the usual shape for spreadsheet analysis. If you need one row per order instead, join the SKUs into a single documented field such as A1|B2 rather than letting an array stringify on its own.

Decide the grain before you touch the tool. One row per order answers revenue questions; one row per line item answers product questions. A mixed file with some orders collapsed and others expanded will produce misleading totals, even when every cell is technically valid.

The reverse direction and the 500KB cap

The same tool converts CSV back to JSON with a local parser. The first row becomes the header keys, duplicate header names get numeric suffixes, and blank headers become generated column names. Values come back as strings, so a price of 19.99 returns as text. The parser also guards spreadsheet formula injection by prefixing cells that start with =, +, - or @ with an apostrophe.

CSV input is capped at 500KB. Anything beyond the cap is truncated before parsing, and the interface warns that only the first part was converted. Split large exports or trim unnecessary columns. The JSON-to-CSV direction is the one to use when you already have structured API data; the CSV-to-JSON direction is for data that started life in a spreadsheet.

A conversion workflow that survives review

  1. Confirm the source is an array, not a wrapper object with a data field. Unwrap it first.
  2. List every key across all records. Note the odd fields that appear in only one row.
  3. Flatten nested objects and choose one row grain before converting.
  4. Convert, then count the header cells and compare them with the key list.
  5. Open the CSV in a spreadsheet and check blank cells, quoted commas and multi-line values.
  6. Keep the original JSON and the flattening logic so the export can be reproduced.

If the CSV opens with every row in one column, the spreadsheet likely ignored the delimiter or the file was saved with a different separator. If columns are shifted, a header name probably contained a comma or a row was edited by hand. Fix the source, not the symptoms.

For large exports, validate the JSON before converting. The parse error fixes save time when the failure is a trailing comma rather than a data shape problem. When URLs or encoded identifiers appear in cells, the URL encoding guide explains why a value may look different after a round trip.

Convert a sample now: open the JSON to CSV converter, paste a flat array and copy the result. The conversion runs locally, with no upload and no account. For the wider toolkit, start with the developer guide.

Frequently asked questions

The converter only writes scalar values. When a JSON value is an object, String(value) produces [object Object], and an array of objects does the same. Flatten the nested fields into separate keys before conversion, or serialize the object as JSON text in a single cell if the spreadsheet truly needs it.

No. It unions top-level keys and leaves nested structure alone, which is why nested objects become [object Object]. Build a flat array first, for example customer_name and customer_city instead of a customer object. Arrays should be joined into a documented single field or expanded into one row per item.

The header includes every key found in any row, in first-seen order. A row missing a key gets an empty cell in that column. Nothing is shifted, because each row is written against the full header. This is why a field that appears in only one record still produces a column.

No. The JSON-to-CSV output is comma-separated, and there is no delimiter setting. If your spreadsheet locale expects semicolons, convert first and handle the separator during import or with a controlled post-processing step. Do not rename the file and assume the format changed.

The header follows the first-seen order of keys across the array, not an alphabetical or template order. A new field in a later record appears after earlier keys. Normalize the objects in the source or reorder the columns in the spreadsheet after conversion if the order matters.

The CSV-to-JSON direction caps input at 500KB and truncates anything beyond it with a warning. Split larger exports before pasting. The JSON-to-CSV direction is intended for normal API-sized arrays; keep huge payloads out of the browser tool and process them in a script.

Done reading — open the JSON ↔ CSV Converter

Convert between JSON and CSV — free in your browser, no signup.

Open JSON ↔ CSV Converter →

Keep reading in this guide

Pillar guide

Debug API Responses Locally: JSON, Base64, JWT, Regex Guide

In this silo

Why JSON.parse Fails: Trailing Commas and Quotes

In this silo

Base64 URL-Safe vs Standard: Padding and Modes

In this silo

URL Encoding: Spaces, Symbols and Double-Escape Bugs