6 min read
By HappyCSV Team

Convert JSON to CSV (Developer's Guide)

Convert JSON files to CSV format easily. Handle nested objects, arrays, and complex structures. Perfect for developers and data analysts.

Convert JSON to CSV (Developer's Guide)

Got JSON data that you need in CSV format? Whether you're exporting API results, converting database dumps, or just need to view JSON data in Excel, I'll show you how to convert JSON to CSV properly.

Why Convert JSON to CSV?

JSON is great for APIs and programming. CSV is great for spreadsheets and databases. Sometimes you need both.

Common scenarios:

  • API response needs to go into Excel
  • JSON database export needs to import into SQL
  • Want to view/edit JSON data in Google Sheets
  • Stakeholders want a spreadsheet, but your data is in JSON

What JSON Structures Convert Well

Simple JSON (Perfect for CSV):

[
  { "name": "John", "email": "john@email.com", "age": 25 },
  { "name": "Sarah", "email": "sarah@email.com", "age": 30 }
]

Converts to:

name,email,age
John,john@email.com,25
Sarah,sarah@email.com,30

Clean and straightforward.

Complex JSON (Needs Flattening):

[
  {
    "name": "John",
    "contact": {
      "email": "john@email.com",
      "phone": "555-1234"
    }
  }
]

Nested objects need to be "flattened" before converting to CSV.

How to Convert JSON to CSV (Quick Method)

Method 1: Online Converter Tool

  1. Copy your JSON
  2. Paste into converter
  3. Download CSV

Pros: Fast, no installation
Cons: Your data goes to someone else's server

Convert JSON to CSV (runs in your browser, data stays private)

Method 2: Python Script

If you code, Python makes this trivial:

import pandas as pd
import json

# Read JSON file
with open('data.json', 'r') as f:
    data = json.load(f)

# Convert to DataFrame
df = pd.DataFrame(data)

# Save as CSV
df.to_csv('output.csv', index=False)

Pros: Scriptable, repeatable
Cons: Requires Python knowledge

Method 3: Excel Power Query

Excel can import JSON directly:

  1. Data → Get Data → From File → From JSON
  2. Select your JSON file
  3. Power Query editor opens
  4. Click "To Table" → "Delimiter: None"
  5. Expand nested columns if needed
  6. Close & Load
  7. Save as CSV

Pros: Uses familiar Excel interface
Cons: Clunky for complex nested JSON

Handling Nested JSON

The tricky part of JSON-to-CSV is nested objects and arrays.

Example: Nested Objects

JSON:

[
  {
    "name": "John",
    "address": {
      "city": "NYC",
      "zip": "10001"
    }
  }
]

Option 1: Flatten with Dot Notation

name,address.city,address.zip
John,NYC,10001

Option 2: Separate Columns

name,city,zip
John,NYC,10001

Most converters use Option 1 (dot notation) because it preserves the structure.

Example: Arrays in JSON

JSON:

[
  {
    "name": "John",
    "skills": ["Python", "SQL", "Excel"]
  }
]

Option 1: Comma-Separated String

name,skills
John,"Python,SQL,Excel"

Option 2: Create Multiple Rows

name,skill
John,Python
John,SQL
John,Excel

Option 1 is cleaner. Option 2 is better for database normalization.

Common JSON-to-CSV Problems

Problem 1: "Array of objects expected"

Error: Your JSON doesn't convert.

Why: The converter expects:

[{ "key": "value" }, { "key": "value" }]

But you have:

{
  "data": [{ "key": "value" }]
}

Fix: Your actual array is inside the data property. Extract that first, or use a converter that lets you specify the path.

Problem 2: Inconsistent Keys

JSON:

[
  { "name": "John", "email": "john@email.com" },
  { "name": "Sarah", "age": 30 }
]

Result:

name,email,age
John,john@email.com,
Sarah,,30

Empty cells where data doesn't exist. This is normal and expected.

Problem 3: Very Nested JSON

JSON:

{
  "user": {
    "profile": {
      "personal": {
        "name": "John"
      }
    }
  }
}

CSV will have column: user.profile.personal.name

Deeply nested JSON creates unwieldy column names. Consider flattening or restructuring before conversion.

Problem 4: JSON is oneobject, not an array

JSON:

{
  "name": "John",
  "email": "john@email.com"
}

Fix: Wrap it in square brackets to make it an array:

[
  {
    "name": "John",
    "email": "john@email.com"
  }
]

Now it'll convert properly.

Best Practices

1. Validate Your JSON First

Before converting, make sure your JSON is valid:

  • Use a JSON validator (jsonlint.com)
  • Check for missing commas, brackets, quotes
  • Ensure proper escaping of special characters

Invalid JSON won't convert and will give cryptic errors.

2. Know Your Structure

Look at your JSON structure:

  • Is it an array of objects? ✓ Perfect for CSV
  • Does it have nested objects? → Needs flattening
  • Does it have arrays as values? → Decide how to handle

Understanding the structure helps you choose the right conversion approach.

3. Handle Special Characters

JSON can contain:

  • Quotes (")
  • Commas (,)
  • Newlines (\n)

A good converter will properly escape these for CSV format:

"Text with ""quotes"" inside"
"Text with commas, inside"

4. Preserve Data Types

JSON has explicit types (string, number, boolean). CSV is all text.

Example:

  • JSON: {"age": 25, "active": true}
  • CSV: age,active25,true

Everything becomes text. Usually fine, but be aware when importing to databases that expect specific types.

Real-World Example: API Response to CSV

You call an API and get:

{
  "users": [
    {
      "id": 1,
      "name": "John Smith",
      "email": "john@company.com",
      "metadata": {
        "signup_date": "2024-01-15",
        "plan": "pro"
      }
    },
    {
      "id": 2,
      "name": "Sarah Jones",
      "email": "sarah@company.com",
      "metadata": {
        "signup_date": "2024-02-20",
        "plan": "free"
      }
    }
  ]
}

Step 1: Extract the users array (the actual data)

Step 2: Flatten the nested metadata:

id,name,email,metadata.signup_date,metadata.plan
1,John Smith,john@company.com,2024-01-15,pro
2,Sarah Jones,sarah@company.com,2024-02-20,free

Step 3: Optionally rename columns:

id,name,email,signup_date,plan
1,John Smith,john@company.com,2024-01-15,pro
2,Sarah Jones,sarah@company.com,2024-02-20,free

Clean, flat CSV ready for Excel or database import.

When JSON-to-CSV Doesn't Make Sense

Sometimes JSON is too complex for CSV:

Deeply nested hierarchies:

{
  "company": {
    "departments": [
      {
        "name": "Sales",
        "teams": [
          {
            "name": "East Coast",
            "members": [...]
          }
        ]
      }
    ]
  }
}

Flattening this creates a mess. Better to:

  • Import directly to a database (keep structure)
  • Process programmatically (Python/JavaScript)
  • Split into multiple related CSV files

Better suited for JSON:

  • Hierarchical data
  • Variable structures
  • Data with complex relationships

Better suited for CSV:

  • Flat, tabular data
  • Consistency across rows
  • Simple key-value pairs

The Bottom Line

Converting JSON to CSV is straightforward for simple structures:

  1. Ensure JSON is an array of objects
  2. Use a converter or script
  3. Handle nested objects (flatten with dot notation)
  4. Handle arrays (comma-separate or expand to rows)

For complex JSON, you might need to:

  • Pre-process to simplify structure
  • Write custom flattening logic
  • Split into multiple CSVs

Quick checklist:

  • ✓ JSON is valid
  • ✓ It's an array of objects (or can be wrapped)
  • ✓ Nested objects are acceptable (will be flattened)
  • ✓ Arrays are few and simple

If yes to all, conversion will be smooth. If not, expect some manual work.


Convert JSON to CSV easily: HappyCSV's JSON converter handles nesting, arrays, and special characters automatically. Browser-based, your data stays private.

Need to handle CSV files?

HappyCSV is the free, secure way to merge, split, and clean your data — all in your browser.