How to Convert JSON to CSV Without Uploading Files
Learn how to convert JSON arrays to CSV format entirely in your browser, with practical examples for flat and nested data structures.
Published September 17, 2024
Converting JSON to CSV is a common task when you need to move data from an API or a NoSQL database into a spreadsheet for analysis. The challenge is that JSON is hierarchical while CSV is tabular, so the conversion requires flattening nested structures. This guide shows how to do this conversion safely in the browser, with examples for both flat and nested JSON.
Why convert JSON to CSV?
CSV (comma-separated values) is the most widely supported format for tabular data. Spreadsheet applications like Excel and Google Sheets, data analysis tools like pandas, and business intelligence platforms all import CSV directly. If you have data in JSON from an API response or a database export, converting it to CSV lets you analyze it in the tools you already use.
JSON is flexible and hierarchical, which makes it great for APIs but less convenient for quick analysis. CSV is rigid and flat, which makes it easy to open in a spreadsheet and sort, filter, and chart. Converting between the two formats bridges the gap between developer data and business analysis.
Understanding the structure difference
JSON supports nested objects and arrays, while CSV is a flat table of rows and columns. A JSON array of objects converts naturally to CSV when each object has the same keys. The keys become column headers, and the values become row cells.
When JSON contains nested objects, the converter must flatten them. For example, an object like {"user":{"name":"Alice","age":30}} can be flattened to columns named user.name and user.age. The converter uses dot notation to create unique column names from the nested structure.
Arrays within objects are trickier. An array of values can be joined into a single cell with a separator, or the object can be duplicated across multiple rows, one for each array element. The right approach depends on the data and how you plan to use the CSV.
Converting flat JSON arrays
A flat JSON array, where each object has the same keys, is the simplest case. For example, an array of user objects with name, email, and role fields converts directly to a CSV with three columns. The converter extracts the keys from the first object to use as column headers, then writes each object as a row.
If objects have different keys, the converter typically unions all keys and leaves missing values blank. This preserves all data but may produce a sparse CSV with many empty cells.
Handling nested objects
Nested objects are flattened using dot notation. For example, {"address":{"city":"Berlin","country":"Germany"}} becomes two columns: address.city and address.country. This preserves the hierarchical information in the column names while keeping the CSV flat.
Deeply nested structures can produce very long column names. If the nesting is deep, consider whether you need all the nested data in the CSV or whether you can extract just the fields you need before converting.
Handling arrays of objects
When an object contains an array of objects, you have two options. The first is to join the array values into a single cell using a separator like semicolons. This keeps one row per top-level object but puts multiple values in a single cell.
The second option is to create one row per array element, duplicating the parent object fields. This produces more rows but keeps each cell scalar. The right choice depends on how you plan to analyze the data in your spreadsheet.
Step-by-step with a browser tool
1. Open a browser-based JSON-to-CSV converter like JSON Toolkit at json.explorme.com.
2. Paste your JSON array into the input area.
3. The tool parses the JSON and displays a preview of the CSV output.
4. Review the column headers and check that nested fields are flattened correctly.
5. If the tool offers options for handling arrays, choose the approach that fits your data.
6. Download the CSV file or copy it to your clipboard.
7. Open the CSV in your spreadsheet application for analysis.
Common mistakes to avoid
- Converting JSON with inconsistent keys without checking the output. Objects with different keys produce sparse CSVs with many empty cells.
- Ignoring how nested arrays are handled. Arrays can be joined into a single cell or expanded into multiple rows. Choose the right approach for your analysis.
- Using a server-side converter for sensitive data. Browser-based tools keep your data on your device.
- Forgetting to check for special characters in values. Values containing commas, quotes, or newlines need proper CSV escaping.
- Assuming all JSON converts cleanly to CSV. Very complex or deeply nested JSON may not produce a useful tabular structure.
FAQ
Related tools
JSON Toolkit
Format, validate, diff, convert, and query JSON in the browser
Learn moreToolKit
54 daily-use tools across 9 categories
Learn moreRelated guides
Looking for more tools? Explore our JSON & Developer Tools category.