json to csvconvert jsoncsv exportdata conversionspreadsheet

How to Convert JSON to CSV: A Complete Beginner's Guide

JSON is great for APIs but spreadsheets need CSV. Learn what JSON to CSV conversion means, when to use it, and how to do it in seconds with a free online tool.

10 min read

Related Tool

JSON to CSV

Open tool

JSON is the language of APIs and modern web services. CSV is the language of spreadsheets and data analysts. There are countless moments in a developer's or analyst's day when data arrives as JSON and needs to leave as a CSV file. This guide explains why, when, and how to do that conversion, with no programming required.

What Is JSON?

JSON stands for JavaScript Object Notation. It is a text-based format for representing structured data using key-value pairs, arrays, and nested objects. A typical JSON response from an API looks like a list of objects, where each object has the same set of keys.

For example, a list of users might be an array where each item has a name key, an email key, and a role key. The values for each key are different for every user. This is the structure that maps most naturally to a CSV file.

What Is CSV?

CSV stands for comma-separated values. It is a plain text format where each line represents one row of data and the values within each row are separated by commas. The first row is usually a header row containing the column names.

CSV files open directly in Microsoft Excel, Google Sheets, LibreOffice Calc, and virtually every data analysis tool in existence. They are also accepted by most database import tools, email marketing platforms, CRM systems, and e-commerce dashboards.

Why Convert JSON to CSV?

There are several common reasons to perform this conversion.

Sharing data with non-developers. Business stakeholders, data analysts, and operations teams often work in spreadsheet applications. Sending them a JSON file is not helpful. Converting to CSV first means they can open the data immediately in a familiar tool.

Importing into a database or CRM. Many database management interfaces accept CSV uploads for bulk data insertion. A CRM like HubSpot or Salesforce can import contacts and leads from a CSV file.

Running analysis in Excel or Google Sheets. Pivot tables, SUMIF formulas, charts, and filters all work on tabular data. CSV is the most universal way to bring data into those tools.

Archiving or reporting. A flat CSV file is easy to store, email, and reference later. It does not require any special viewer.

What JSON Structure Works Best for CSV Conversion?

The JSON structure that converts most cleanly to CSV is a flat array of objects where every object has the same keys.

A flat array means the top level of the JSON is a list (array) of items. Each item is an object with properties. Every object in the list should have the same properties. When this structure is present, the keys of the first object become the column headers, and the values from every subsequent object fill in the rows.

Deeply nested JSON is harder to convert because CSV is a flat two-dimensional format. A JSON object where each item contains a nested sub-object (like an address with its own street, city, and zip fields) will be flattened by a good converter, turning the nested keys into compound column names like address.city and address.zip.

Arrays nested inside objects are the most challenging case. A user object that contains an array of orders cannot be represented cleanly in a single CSV row because one row can contain only a single value per column. Most converters either expand the nested array into multiple rows or convert the array to a string representation.

How to Convert JSON to CSV Using DevHexLab

The DevHexLab JSON to CSV tool handles the conversion in your browser with no software to install and no account required.

Open the tool at /tools/json/json-to-csv. Paste your JSON array into the input field on the left. The tool reads the structure and generates the CSV output on the right. You can click Download CSV to save the file, or Copy to grab the text and paste it directly into a spreadsheet.

The tool automatically detects the column names from the keys of the first object. It handles values that contain commas or line breaks by wrapping them in double quotes. It also handles null values and boolean values by converting them to their string equivalents.

What Happens to Special Characters?

If a value in your JSON contains a comma, a double quote, or a newline character, those characters would break a naive CSV file. The tool handles this correctly by applying the standard CSV quoting rules.

A value that contains a comma is wrapped in double quotes so the comma is treated as part of the value rather than a column separator.

A value that already contains a double quote has the quote doubled (two consecutive quote characters) so the CSV parser knows the quote is part of the value.

A value that contains a newline is wrapped in double quotes and the newline is preserved. Most spreadsheet applications handle this correctly and display the multi-line value within a single cell.

Manually Converting JSON to CSV

If you want to understand what the tool is doing, the manual process is straightforward.

Take the array of objects and identify all the unique keys. Those become the first row (header row) of your CSV, with each key separated by a comma.

For each object in the array, write one row where the values appear in the same order as the headers. If an object is missing a key that other objects have, leave the value empty (just put two commas next to each other with nothing between them).

Wrap any value that contains a comma, a quote, or a newline in double quotes.

This is exactly what the DevHexLab tool does automatically, which is why using it saves you from writing this logic yourself.

Converting JSON to CSV in Code

If you need to automate this conversion inside a script, most programming languages make it straightforward.

In JavaScript (Node.js), you would parse the JSON string into an array, extract the headers from the first object's keys, then use a loop to build each row. A library like papaparse simplifies this considerably.

In Python, the csv module provides a DictWriter class that accepts a list of dictionaries and writes them to a CSV file automatically.

In shell environments, the command-line tool jq can extract fields from JSON and pipe them into a formatted output, though complex nesting still requires custom handling.

For one-off conversions or when you do not want to write code, the DevHexLab tool is far faster.

Frequently Asked Questions

Can I convert nested JSON to CSV?

Yes, with some limitations. Flat nested objects (an object inside an object) can be flattened into dot-notation column names. Arrays inside objects are harder and may be converted to string representations or expanded into multiple rows depending on the tool.

What if my JSON objects have different keys?

The DevHexLab tool uses the union of all keys found across all objects as the column headers. Objects that are missing a key will have an empty value for that column.

Is there a file size limit?

The DevHexLab JSON to CSV tool runs entirely in your browser, so the practical limit is the amount of memory available to your browser tab. Most JSON files up to several megabytes convert without any issue.

Can I paste just one JSON object instead of an array?

Most converters expect an array of objects. A single object would produce a CSV with one data row. If you need to convert a single object, wrap it in square brackets to make it a one-item array before pasting.

From API Response to Spreadsheet in Seconds

JSON and CSV are both valuable formats for different audiences and different tools. Understanding how to move between them lets you work more fluidly across the full data pipeline: from the API that produces the data to the spreadsheet where a colleague analyses it. Open the DevHexLab JSON to CSV tool, paste your data, and have a ready-to-use CSV file in under ten seconds.