Skip to main content
Tools Star Hub

Developer Tools

How to Turn a JSON Array into CSV

By Tools Star Hub Editorial Team · Published · Updated

JSON becomes CSV on this page only when the text is an array of objects. The JSON to CSV tool reads the keys as the header row and writes one CSV row per object. [{"name":"Ada","id":1},{"name":"Lin","id":2}] becomes a header of name,id and two data rows, Ada,1 and Lin,2. A single object, an empty array, or an array of numbers is rejected.

Spreadsheets expect a header and rows. JSON often arrives as an array of records. Converting that shape locally lets you open the result in a spreadsheet without uploading the text. Nested values are not flattened into extra columns. They are written as JSON text inside one cell.

What shape of JSON does the converter accept?

The text must be valid JSON, and the top value must be an array. Each item must be an object, not an array, a string, or null. An empty array fails with the message that there are no rows to convert. An object with no keys fails because there is nothing to put in a header.

Keys are collected in the order they first appear. A later object can add a new column. A missing key becomes an empty cell. null and undefined also become empty cells. true and false become the words true and false. A number is written as its digits.

How to Turn a JSON Array into CSV — Tools Star Hub

When does a cell get quotes?

A cell is wrapped in double quotes when it contains a comma, a double quote, or a line break. A double quote inside the cell is doubled. That is ordinary CSV escaping, so a spreadsheet can tell the comma belongs to the cell and not to the column break.

A nested object or array is passed through JSON.stringify and then escaped if needed. The converter does not invent columns for street and city inside an address object. If you need those as separate columns, reshape the JSON first so each field is a top-level key.

What will the converter refuse?

Comments, single-quoted keys, and trailing commas are not JSON, so the page says the text is not valid JSON. A top-level object such as {"name":"Ada"} is valid JSON and still fails, because the converter asks for an array of objects.

The result is text you can copy. It does not open a spreadsheet for you, and it does not send the JSON to a server. If the records are already CSV, use the CSV to JSON tool in the other direction.

How to turn a JSON array into CSV

  1. Paste an array of objects. The first character after any surrounding space should be an opening bracket. Format the JSON first if you are not sure it parses.
  2. Check that every item is an object. A number, a string, null, or a nested array in the top list stops the conversion and names the item number.
  3. Read the header. The first row is the keys, in first-seen order. Later keys are added to the right. Missing keys stay blank.
  4. Copy the CSV. Quoted cells already follow the comma and quote rules. Open the text in a spreadsheet if you want to check the columns.

Example

Two flat records

The array [{"name":"Ada","id":1},{"name":"Lin","id":2}] converts to name,id followed by Ada,1 and Lin,2. The tool reports 2 rows and the columns name and id.

A comma inside a name

A name such as Ada, Lin is written as a quoted cell, with the comma kept inside the quotes. The header stays a single name column.

Common mistakes

A lone object is not a table

Wrap one record in brackets if you want one data row. {"name":"Ada"} is valid JSON and still not the shape this converter accepts.

Nested fields stay in one cell

An address object becomes JSON text in that column. It does not split into street and city columns.

FAQ

Why does an empty array fail?
There are no objects to read keys from, so there is no header. The page says the array is empty and there are no rows to convert.
What happens to a missing key?
The column still exists if some other object has that key. The missing value is an empty cell.
Are nested objects expanded?
No. A nested object or array is placed in one cell as JSON text, then quoted if the cell contains a comma, quote, or line break.
Do I need a spreadsheet?
No. The page returns CSV text. A spreadsheet is only a way to check the columns after you copy the result.
Does the conversion leave the browser?
No. The JSON to CSV tool parses and writes the text in this tab.

To turn an array of objects into a header and rows, use the JSON to CSV converter. It keeps the work in the browser.

If the text will not parse, start with What is JSON?.

To go the other way, see how to convert CSV to JSON.