Blog

Tips, tutorials, and insights about online tools

How to Convert JSON to CSV for Excel & Spreadsheets
2026-08-20Keynou Team

How to Convert JSON to CSV for Excel & Spreadsheets

JSON is the format APIs and applications speak. But when you need to analyze data, share it with non-technical colleagues, or import it into a spreadsheet, CSV is what they expect. When you convert JSON to CSV, the challenge isn't the conversion itself — it's handling nested objects, arrays, and inconsistent structures without losing data. A browser-based converter flattens JSON into clean, spreadsheet-ready CSV instantly. This guide covers the flattening process, array handling, delimiter options, Excel compatibility, and practical code examples.

Why Convert JSON to CSV?

JSON supports nested objects and arrays. CSV is flat — rows and columns only. The conversion requires flattening nested structures into column names and handling arrays in a way that preserves the data without breaking the tabular format.

Common scenarios where you need to convert JSON to CSV:

  • API response analysis — export API data to Excel for filtering, sorting, and pivot tables
  • Data sharing — send data to colleagues who work in spreadsheets, not code
  • Database export — move JSON documents into a relational database via CSV import
  • Reporting — generate CSV reports from JSON data for business intelligence tools

Step 1: Understand the Flattening Process

Nested JSON objects need to be flattened into dot-notation column headers. This preserves the hierarchy while keeping the data tabular.

[
  {
    "name": "Alice",
    "age": 30,
    "address": {
      "city": "New York",
      "zip": "10001"
    }
  },
  {
    "name": "Bob",
    "age": 25,
    "address": {
      "city": "Los Angeles",
      "zip": "90001"
    }
  }
]

Flattens to:

name,age,address.city,address.zip
Alice,30,New York,10001
Bob,25,Los Angeles,90001

The JSON to CSV converter handles this flattening automatically. Paste your JSON, and the converter identifies all unique key paths across every object, builds the column headers, and outputs the CSV.

Handling Inconsistent Keys

Real-world JSON rarely has perfectly consistent keys. One object might have "middle_name" while another doesn't. The converter handles this by:

  • Collecting all unique keys across every object in the array
  • Building a superset of columns — every key that appears in any object becomes a column
  • Filling missing values with empty strings — objects that lack a key get a blank cell
[
  { "name": "Alice", "email": "alice@example.com" },
  { "name": "Bob", "phone": "555-0100" }
]

Produces:

name,email,phone
Alice,alice@example.com,
Bob,,555-0100

Step 2: Handle Arrays in JSON

Arrays are the trickiest part of converting JSON to CSV. A CSV row can't contain multiple values for the same column. There are several strategies:

Strategy 1: Join Array Values

Join array elements with a separator (usually a pipe | or semicolon ;):

{ "name": "Alice", "tags": ["vip", "newsletter", "beta"] }

Becomes:

name,tags
Alice,vip|newsletter|beta

This is the most common approach. It keeps the data in a single row and lets you split the values later in your spreadsheet using TEXT TO COLUMNS or a formula.

Strategy 2: Flatten with Index Notation

Use numeric indices in column headers, similar to dot notation for nested objects:

{ "name": "Alice", "orders": [{"id": "ORD001", "total": 99.50}] }

Becomes:

name,orders.0.id,orders.0.total
Alice,ORD001,99.50

This works well when arrays have a predictable, small number of elements. It breaks down with variable-length arrays — some rows will have orders.0.id through orders.5.id while others have only orders.0.id.

Strategy 3: Expand to Multiple Rows

For arrays of objects, create one CSV row per array element, repeating the parent fields:

name,orders.id,orders.total
Alice,ORD001,99.50
Alice,ORD002,45.00

This is useful when each array element is a standalone record (like line items in an order). The JSON to CSV converter lets you choose the strategy that fits your data.

Step 3: Choose the Right Delimiter

CSV stands for "comma-separated values," but Excel handles different delimiters differently depending on your locale:

  • Comma (,) — standard CSV, but Excel in European locales may interpret commas as decimal separators, misaligning columns
  • Semicolon (;) — the default Excel delimiter in many European locales (France, Germany, Spain)
  • Tab (\t) — TSV format, rarely conflicts with data content
  • Pipe (|) — safe delimiter when your data contains both commas and semicolons

If your JSON values contain the delimiter character, the converter wraps them in quotes: "Smith, John". This is standard CSV escaping — Excel and Google Sheets handle it correctly.

Step 4: Ensure Excel Compatibility

Excel has specific quirks when opening CSV files. Here's how to avoid common issues:

UTF-8 Encoding with BOM

Excel on Windows expects a Byte Order Mark (BOM) at the start of UTF-8 files. Without it, non-ASCII characters (é, ñ, 中) display as garbled text. The converter adds the BOM automatically so Excel interprets the encoding correctly.

Date Formatting

Excel auto-detects dates and reformats them. A value like 2026-08-20 might display as 8/20/2026. To prevent this, prefix dates with a single quote in your JSON data, or format the column as text after importing.

Large Numbers

Excel truncates large numbers to 15 significant digits and converts them to scientific notation. A 20-digit ID like 12345678901234567890 becomes 1.23457E+19. To preserve exact values, store large numbers as strings in your JSON before conversion.

Leading Zeros

Values like 007 or 00123 lose leading zeros in Excel because they're treated as numbers. Store them as strings in JSON, or format the CSV column as text after import.

Converting JSON to CSV in Code

For programmatic conversion, here's a JavaScript function that flattens and converts:

function flattenObject(obj, prefix = '') {
  let result = {};
  for (const key in obj) {
    const value = obj[key];
    const newKey = prefix ? `${prefix}.${key}` : key;
    if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
      Object.assign(result, flattenObject(value, newKey));
    } else if (Array.isArray(value)) {
      result[newKey] = value.join('|');
    } else {
      result[newKey] = value;
    }
  }
  return result;
}

function jsonToCsv(jsonArray) {
  const flatObjects = jsonArray.map(obj => flattenObject(obj));
  const headers = [...new Set(flatObjects.flatMap(obj => Object.keys(obj)))];
  const csvRows = [headers.join(',')];
  for (const obj of flatObjects) {
    const row = headers.map(h => {
      const val = obj[h] ?? '';
      return String(val).includes(',') ? `"${val}"` : val;
    });
    csvRows.push(row.join(','));
  }
  return csvRows.join('\n');
}

For production use, consider a library like json2csv which handles edge cases, streaming, and custom field selection. You can also validate your JSON first with the JSON formatter to catch syntax errors before conversion.

Tips for Clean Conversion

  1. Validate your JSON first — invalid JSON produces errors; run it through the JSON formatter to check
  2. Review array handling — choose the strategy that matches your downstream use case
  3. Check for nested depth — deeply nested objects produce very long column names; consider simplifying your JSON structure first
  4. Test with a small sample — convert 5-10 records first to verify the output before processing the full dataset
  5. Use the right delimiter — switch to semicolon or tab if your data contains commas

Common Use Cases

  • API data export — convert API responses to CSV for analysis in Excel or Google Sheets
  • Data migration — move JSON documents into relational databases that accept CSV import
  • Reporting — generate spreadsheet-friendly reports from JSON data sources
  • Backup — create human-readable CSV exports of JSON data stores

Published: August 20, 2026
Category: Data Tools
Reading Time: 7 minutes

Verified DR - Verified Domain Rating for keynou.com
FlowDrive