Building AI Agent? Test & Secure your AI Agent now. Request access
API Testing5 min read

How to Convert JSON to CSV — Methods, Tools & Code Examples

S
Shreya Srivastava
Content Team
Updated on: February 2026

How to Convert JSON to CSV: Quick Methods

Converting JSON to CSV is one of the most common data transformation tasks. Whether you need to analyze API data in Excel, export database records for a report, or prepare training data for machine learning, here are the fastest methods:

Method

Best For

Skill Level

Qodex JSON to CSV Converter

Quick, one-off conversions

No coding required

Python (pandas)

Large datasets, automation

Basic Python

JavaScript (json2csv)

Node.js projects, API pipelines

Basic JavaScript

Command line (jq + miller)

Shell scripting, quick transforms

CLI familiarity

Excel Power Query

Non-technical users

No coding required

Method 1: Free Online Converter (No Code)

The fastest way to convert JSON to CSV is with Qodex's free JSON to CSV Converter:

  1. Paste your JSON data or upload a .json file

  2. The tool automatically detects the structure and flattens nested objects

  3. Download the resulting CSV file

This method works best for quick, one-off conversions of small to medium datasets. No account required, no data stored on servers.

For the reverse conversion, use the CSV to JSON Converter. For a deeper comparison of these formats, see our CSV vs JSON comparison.

Method 2: Python with pandas

Python's pandas library is the most popular choice for programmatic JSON-to-CSV conversion, especially for large datasets or automated pipelines:

import pandas as pd
import json

Simple flat JSON array

data = [ {"name": "Alice", "email": "alice@example.com", "age": 30}, {"name": "Bob", "email": "bob@example.com", "age": 25} ] df = pd.DataFrame(data) df.to_csv("output.csv", index=False)

From a JSON file

df = pd.read_json("data.json") df.to_csv("output.csv", index=False)

Nested JSON — flatten first

with open("nested.json") as f: data = json.load(f) df = pd.json_normalize(data) # Flattens nested objects df.to_csv("output.csv", index=False)

Key function: pd.json_normalize() handles nested JSON by flattening it into dot-notation columns (e.g., address.city, address.zip). This is essential for converting real-world API responses that are rarely flat.

Method 3: JavaScript with json2csv

For Node.js projects or data pipelines built in JavaScript:

const { Parser } = require('json2csv');

const data = [ { name: "Alice", email: "alice@example.com", age: 30 }, { name: "Bob", email: "bob@example.com", age: 25 } ];

// Basic conversion const parser = new Parser(); const csv = parser.parse(data); console.log(csv);

// With nested data — specify flattening const { Parser } = require('json2csv'); const opts = { fields: ['name', 'address.city', 'address.zip'], unwind: ['orders'], // Expand arrays into multiple rows }; const parser = new Parser(opts); const csv = parser.parse(nestedData);

The json2csv library handles most common JSON structures including nested objects, arrays, and mixed types. Install with npm install json2csv.

Method 4: Command Line

For shell scripting and quick one-liners, combine jq (JSON processor) with standard tools:

# Using jq to convert flat JSON array to CSV
cat data.json | jq -r '
  (.[0] | keys_unsorted) as $keys |
  ($keys | @csv),
  (.[] | [.[$keys[]]] | @csv)
' > output.csv

Using miller (mlr) — purpose-built for format conversion

mlr --json2csv cat data.json > output.csv

Using Python one-liner

python3 -c "import pandas as pd; pd.read_json('data.json').to_csv('output.csv', index=False)"

Miller (mlr) is especially useful for data format conversion — install with brew install miller (macOS) or apt install miller (Ubuntu).

Handling Nested JSON

Real-world JSON from API endpoints is rarely flat. Here's how to handle common nested structures:

Nested Objects → Dot-Notation Columns

// Input JSON
{"name": "Alice", "address": {"city": "NYC", "zip": "10001"}}

// Output CSV name,address.city,address.zip Alice,NYC,10001

Arrays → Multiple Rows or Delimited Strings

// Input JSON
{"name": "Alice", "tags": ["admin", "editor"]}

// Option A: Multiple rows (unwind) name,tags Alice,admin Alice,editor

// Option B: Delimited string name,tags Alice,"admin;editor"

Mixed Nesting → Flatten + Unwind

For deeply nested JSON, use a two-step approach: first flatten objects with json_normalize(), then unwind arrays into separate rows. This preserves all data while creating a valid tabular structure.

Understanding the structural differences between these formats helps you choose the right conversion approach. See our CSV vs JSON comparison for a deeper dive into the trade-offs.


Frequently Asked Questions

Can I convert nested JSON to CSV?

Yes, but nested JSON requires flattening. Nested objects are typically converted to dot-notation column names (e.g., address.city), and arrays can either be expanded into multiple rows or joined into delimited strings. Python's pandas.json_normalize() and the json2csv Node.js library handle most nesting patterns automatically. For quick conversions, Qodex's JSON to CSV Converter handles nested structures automatically.

What data is lost when converting JSON to CSV?

CSV cannot represent data types (everything becomes text), nested structures (flattened to dot-notation or multiple rows), null vs empty string distinctions, or boolean values (become the strings "true"/"false"). If you need to preserve these distinctions, consider keeping a JSON copy alongside the CSV, or using a format that supports types like Parquet or NDJSON.

How do I convert a large JSON file to CSV?

For large files (100MB+), avoid loading the entire file into memory. Use streaming approaches: Python's ijson library for incremental parsing, or process NDJSON (one JSON object per line) with line-by-line reading. For very large datasets, tools like Apache Spark or DuckDB can convert JSON to CSV efficiently with minimal memory usage.

How do I convert JSON API responses to CSV?

Most API responses return JSON arrays of objects, which map directly to CSV rows. Use Python's requests library to fetch the data and pandas to convert: pd.DataFrame(response.json()).to_csv('output.csv'). For paginated APIs, collect all pages into a list before converting. For API testing workflows, Qodex.ai can export test results directly to CSV.

What is the best JSON to CSV converter?

For quick, no-code conversions: Qodex's JSON to CSV Converter (free, no account needed). For programmatic conversion in Python: pandas with json_normalize(). For JavaScript/Node.js: the json2csv npm package. For command-line: miller (mlr --json2csv). Choose based on your use case — one-off vs automated, small vs large files, flat vs nested JSON.

Can I convert CSV back to JSON?

Yes. The reverse conversion is straightforward for flat data — each CSV row becomes a JSON object with column headers as keys. Use Qodex's CSV to JSON Converter for quick conversions, or pandas.read_csv('data.csv').to_json() in Python. Note that CSV-to-JSON conversion always produces flat objects; if you need nested structures, you'll need to write custom transformation logic.


Discover, Test, & Secure your APIs 10x Faster than before

Auto-discover every endpoint, generate functional & security tests (OWASP Top 10), auto-heal as code changes, and run in CI/CD - no code needed.