Guides

How to Convert JSON to CSV: Complete Step-by-Step Guide

6 min read
January 22, 2026
convert json to csv, json to csv online, json to csv converter

Need to open JSON data in Excel or import it into a database? Converting JSON to CSV is the solution. CSV files are universally supported by spreadsheet applications, databases, and data analysis tools.

This guide shows you how to convert JSON to CSV, handle nested objects, and avoid common pitfalls.

Why Convert JSON to CSV?#

There are several compelling reasons to convert JSON to CSV:

  • Excel/Sheets Compatibility — Open data in any spreadsheet application
  • Smaller File Size — CSV is 50-60% smaller than equivalent JSON
  • Database Import — Most databases have native CSV import
  • Data Analysis — Tools like Pandas, R, and Tableau prefer CSV
  • Non-Technical Users — Business users can open CSV directly
size-comparison.txttext
JSON file: 10,240 bytes
CSV file:   4,096 bytes

Savings: 60%

Basic JSON to CSV Conversion#

A JSON array of objects converts naturally to CSV rows:

input.jsonjson
[
  {"name": "John", "email": "john@example.com", "age": 30},
  {"name": "Jane", "email": "jane@example.com", "age": 25},
  {"name": "Bob", "email": "bob@example.com", "age": 35}
]

Handling Nested Objects (Flattening)#

CSV can only represent flat data, so nested JSON objects must be flattened. The standard approach uses dot notation:

nested-input.jsonjson
[
  {
    "name": "John",
    "address": {
      "city": "New York",
      "zip": "10001"
    }
  }
]

// Converts to CSV:
name,address.city,address.zip
John,New York,10001

Step-by-Step: Using Our Converter#

The easiest way to convert JSON to CSV is using our free online converter:

  1. Paste or upload your JSON data in the left panel
  2. Click "Convert" — conversion happens instantly in your browser
  3. Review the output — nested objects are automatically flattened
  4. Download — Click the download button to save as .csv

Privacy Note: All conversion happens in your browser. Your data never leaves your device.

Programmatic Conversion (Code)#

For automation, here's how to convert JSON to CSV in JavaScript:

function jsonToCsv(jsonData) {
  const data = JSON.parse(jsonData);
  if (!Array.isArray(data) || data.length === 0) {
    throw new Error('Input must be a non-empty array');
  }
  
  // Get all unique keys (headers)
  const headers = [...new Set(data.flatMap(obj => Object.keys(obj)))];
  
  // Create CSV rows
  const rows = data.map(obj => 
    headers.map(header => {
      const value = obj[header] ?? '';
      // Escape quotes and wrap in quotes if contains comma
      const escaped = String(value).replace(/"/g, '""');
      return escaped.includes(',') ? `"${escaped}"` : escaped;
    }).join(',')
  );
  
  return [headers.join(','), ...rows].join('\n');
}

Common Issues & Solutions#

Issue 1: Arrays inside objects

Arrays don't convert cleanly to CSV. Options:

  • Join array values: ["a","b"]"a;b"
  • Create separate columns: tags.0, tags.1
  • Stringify: Store as JSON string in cell

Issue 2: Special characters

Commas, quotes, and newlines in values must be handled:

  • Wrap values containing commas in double quotes
  • Escape quotes by doubling them: ""

Issue 3: Excel encoding

For proper UTF-8 support in Excel, add a BOM (Byte Order Mark) at the start of the file.

Best Practices#

  1. Validate JSON first — Ensure your JSON is valid before conversion
  2. Check for consistent structure — All objects should have similar keys
  3. Use ISO dates — YYYY-MM-DD format is unambiguous
  4. Be careful with numbers — Leading zeros may be stripped by Excel
  5. Test with small data — Verify output before processing large files

Frequently Asked Questions

Can I convert nested JSON to CSV?
Yes, nested objects are flattened using dot notation. For example, {"user": {"name": "John"}} becomes a column called "user.name" with value "John".
Is the conversion reversible?
You can convert CSV back to JSON, but it will be a flat array of objects. Nested structures from the original JSON (represented via dot notation) can be reconstructed with proper parsing.
How large a JSON file can I convert?
Our converter runs entirely in your browser, so it depends on your device's memory. Most devices handle files up to 50-100MB without issues.
Will my data be uploaded to a server?
No, all conversion happens locally in your browser using JavaScript. Your data never leaves your device.

Convert JSON to CSV Now

Try our free, privacy-first JSON to CSV converter. Handles nested objects, large files, and includes bidirectional conversion.

Open JSON to CSV Converter

Related Articles