JSON to CSV Converter
Convert a JSON array of objects into a clean CSV file. Optionally flatten nested objects using dot notation.
[{"name":"A","age":1},{"name":"B","age":2}]). If your JSON is a single object, wrap it in an array first.
What is a JSON to CSV Converter?
A JSON to CSV converter is a tool that transforms data from JavaScript Object Notation (JSON) into Comma-Separated Values (CSV). JSON is the standard format for APIs and web data. CSV is the universal format for spreadsheets (Excel, Google Sheets) and data analysis. Converting between the two is one of the most common data preparation tasks in modern development, data analysis, and DevOps.
At first glance, the conversion seems trivial: just map the JSON keys to column headers and the values to rows. However, real-world JSON from APIs, databases, and web scrapers almost always contains nested objects and arrays. CSV, by design, is a flat, two-dimensional table. It has no concept of a nested structure. This mismatch is the source of nearly every "JSON to CSV" problem developers face. A good converter must make intelligent decisions about how to flatten that nesting.
Why Convert JSON to CSV?
You convert JSON to CSV for one simple reason: human analysis. While developers and machines read JSON efficiently, humans read spreadsheets. When you need to:
- Analyze API data in Excel or Google Sheets, you need CSV.
- Share data with non-technical stakeholders (marketers, managers, clients) who live in Excel, CSV is the language they speak.
- Perform quick data cleaning or filtering, a spreadsheet is often faster than writing a script.
- Import data into a legacy system or CRM that only accepts CSV uploads.
Converting JSON to CSV is the bridge between the machine-readable web and the human-readable spreadsheet.
The Core Challenge: Flattening Nested JSON
Consider this JSON: {"user": {"name": "Ana", "address": {"city": "Lisbon"}}, "tags": ["a","b"]}. CSV has no way to represent the nested address object or the tags array directly. A converter must choose a strategy. The two most common strategies are:
- Dot-Notation Flattening (Recommended): The nested keys are merged into the column header using dots.
user.address.citybecomes a column header, and "Lisbon" becomes the cell value. This is the preferred approach because it preserves data in separate columns, making it queryable and sortable in a spreadsheet. - Stringification: The entire nested object is converted into a JSON string and placed in a single cell. For example, the
addresscell would contain{"city":"Lisbon"}as a string. This is less useful because the data is trapped in a text blob and cannot be easily filtered or analyzed.
This tool defaults to dot-notation flattening because it is the only strategy that produces a genuinely useful CSV for data analysis.
Common Pitfalls and How to Avoid Them
- Heterogeneous Arrays: If your JSON array contains objects with different keys (e.g., one object has a "phone" field, another does not), the converter must create a union of all keys for the header row. Missing values become empty cells. Our tool handles this automatically.
- Excel's 1,048,576 Row Limit: Excel cannot open a CSV with more than 1,048,576 rows. If your JSON array is larger than that, the conversion will succeed, but Excel will fail to open the file. For large datasets, split the JSON into multiple files or use a database tool instead of a spreadsheet.
- Quoting and Escaping: CSV fields that contain commas, quotes, or newlines must be wrapped in double quotes, and internal double quotes must be escaped by doubling them. A naive converter will produce corrupted CSV. This tool uses a proper CSV escaping function to ensure compatibility with Excel and Google Sheets.
JSON vs. CSV: When to Use Which
JSON and CSV are not competitors; they are tools for different jobs. Use JSON when you need to represent complex, nested data structures, when you are transmitting data between a server and a web application, or when your data includes arrays and objects. Use CSV when your data is a flat table, when you need to open it in a spreadsheet, or when you are importing data into a system that requires a tabular format. The ability to move between the two formats is a fundamental data literacy skill.
How to Use This Tool
- Paste Your JSON: Paste a JSON array of objects into the input textarea. If your JSON is a single object, wrap it in square brackets:
[{ ... }]. - Choose Flattening: Leave "Flatten nested objects" checked if your JSON contains nested data. If you want nested objects to appear as raw JSON strings in single cells, uncheck it.
- Select Delimiter: Choose comma, semicolon, or tab, depending on the system you are importing into (Excel typically uses comma).
- Convert: Click "Convert to CSV". The tool will parse the JSON, build the header row, and generate the CSV output.
- Copy or Download: Use the "Copy CSV" button to paste it directly into a spreadsheet, or click "Download .csv" to save the file.
Frequently Asked Questions
How do I convert nested JSON to CSV?
Use a converter that supports dot-notation flattening. Nested keys like user.address.city are merged into a single column header, and the value "Lisbon" is placed in the cell. This tool does this automatically when the "Flatten nested objects" option is checked.
Can I convert JSON to CSV without coding?
Yes. This tool is entirely point-and-click. Paste your JSON, click Convert, and copy the CSV. No programming knowledge is required.
Is my JSON data sent to a server?
No. This tool runs entirely in your browser using client-side JavaScript. Your JSON data never leaves your device and is not logged or stored anywhere.
What happens if my JSON objects have different keys?
The tool creates a header row that is the union of all keys found across all objects. For objects that do not have a particular key, the corresponding cell is left empty.
Why does my CSV have empty cells?
Empty cells appear when an object in the array is missing a key that exists in other objects. This is normal for heterogeneous data. The column still exists, but the value is empty for that row.
Does this tool handle arrays inside JSON?
If an array is encountered inside an object (e.g., {"tags": ["a","b"]}), the array is serialized into a string (e.g., "a;b") and placed in a single cell. CSV cannot represent a true nested array.
Can I convert JSON that is not an array?
The tool expects an array of objects. If you have a single JSON object, wrap it in square brackets: [{"key": "value"}]. The tool will then produce a CSV with one row of data.
Why is my CSV file not opening correctly in Excel?
If your data contains commas, quotes, or newlines, they must be properly escaped. This tool uses standard CSV quoting (RFC 4180) to ensure compatibility. If Excel still misinterprets the file, try using a semicolon delimiter or opening the file via Excel's "Data > From Text" import wizard.
Is there a limit to the JSON size I can convert?
The tool runs in your browser, so the limit depends on your device's available memory. Most modern browsers can handle several megabytes of JSON without issue. For very large files (e.g., >50MB), you may need a command-line tool like jq or json2csv.
What is the difference between flattening and stringifying nested JSON?
Flattening (dot notation) creates separate columns for each nested key (e.g., user.name, user.age). Stringifying keeps the entire nested object as a JSON string in one cell. Flattening is almost always more useful for data analysis because it allows you to sort and filter individual nested values.
Can I use this tool to convert CSV back to JSON?
This tool is specifically for JSON to CSV. If you need the reverse direction, you will need a separate CSV to JSON converter. (You could build that as your next tool!)
Why does my CSV have extra columns I did not expect?
If your JSON contains nested objects and flattening is enabled, the tool creates a column for every unique nested key. If different objects have different nested structures, you will get columns for all of them, with empty cells where the key is missing.
How do I handle a JSON array that contains primitive values (not objects)?
If your array contains primitives (e.g., ["a", "b", "c"]), the tool will create a single column named "value" and list each primitive as a row. This is the expected behavior for non-object JSON arrays.
Does this tool support JSON Lines (JSONL/NDJSON)?
No, this tool expects a standard JSON array. If you have a JSONL file (one JSON object per line), you would need to first combine the lines into an array or use a dedicated JSONL converter.
Can I download the CSV as a file?
Yes. After conversion, click the "Download .csv" button. The tool will generate a file named data.csv and trigger a download in your browser.
Why are some values wrapped in double quotes?
Values are wrapped in double quotes if they contain a comma, a double quote, or a newline. This is required by the CSV standard (RFC 4180) to prevent the spreadsheet software from misinterpreting the data as multiple columns or rows.
Can I choose a different delimiter (semicolon or tab)?
Yes. Use the "Delimiter" dropdown to choose between comma, semicolon, and tab. This is useful for regions where the comma is used as a decimal separator, or for systems that expect tab-separated files (TSV).
What happens to dates and numbers?
The tool performs a direct string conversion. Dates and numbers remain as they are in the JSON (e.g., a Unix timestamp remains a number, an ISO date string remains a string). It does not attempt to reformat or interpret dates.
Is this tool free to use?
Yes. It is completely free, requires no sign-up, and has no usage limits. It runs entirely in your browser, so there are no server costs to pass on to you.
Can I use this tool on my phone?
Yes. The tool is fully responsive and works on mobile browsers. However, for very large JSON files, a desktop browser is recommended for better performance.
Why is the output not showing up?
Check for syntax errors in your JSON. Common issues include trailing commas, missing quotes, or unescaped special characters. The tool will display an error message if the JSON is invalid.
What is the maximum number of rows this tool can handle?
There is no hard limit imposed by the tool. The practical limit is your browser's memory. For reference, Excel itself limits CSV files to 1,048,576 rows. If your data exceeds that, you will need a database or a specialized data tool.
No comments:
Post a Comment