How to Convert JSON to CSV (and Back): Complete Guide

Utilko Team 4 min read Converters

JSON vs CSV: When to Use Each

JSON (JavaScript Object Notation) and CSV (Comma-Separated Values) are two of the most popular data formats, but they serve different purposes:

  • JSON supports nested structures, arrays, and mixed data types. It is ideal for APIs, configuration files, and complex data.
  • CSV is a flat, tabular format. It is ideal for spreadsheets, data analysis, database imports, and simple record-keeping.

Converting between them is a common task when moving data between web applications (which prefer JSON) and tools like Excel, Google Sheets, or database import utilities (which prefer CSV).

How to Convert JSON to CSV

Step 1: Understand Your JSON Structure

JSON-to-CSV conversion works best when your JSON is an array of flat objects:

[
  {"name": "Alice", "age": 30, "city": "NYC"},
  {"name": "Bob", "age": 25, "city": "LA"}
]

Each object becomes a row, and each key becomes a column header.

Step 2: Handle Nested Data

If your JSON has nested objects or arrays, you need to flatten them first. For example, {"address": {"street": "Main St", "zip": "10001"}} could become address.street and address.zip columns.

Step 3: Use a Converter Tool

Paste your JSON into a converter, configure options (delimiter, quote character, header row), and download the CSV result.

Try It Now

Use our free JSON to CSV converter to transform data instantly in your browser.

JSON to CSV → CSV to JSON →

How to Convert CSV to JSON

The reverse process is equally straightforward:

  1. The first row of the CSV is treated as the header, providing the keys for each JSON object.
  2. Each subsequent row becomes a JSON object with key-value pairs.
  3. Values are typically all strings unless the tool auto-detects numbers and booleans.

Programmatic Conversion

JavaScript / Node.js (JSON to CSV)

const data = [{name: "Alice", age: 30}, {name: "Bob", age: 25}];
const headers = Object.keys(data[0]).join(",");
const rows = data.map(obj => Object.values(obj).join(","));
const csv = [headers, ...rows].join("\n");

Python (JSON to CSV)

import csv, json
data = json.load(open("data.json"))
with open("data.csv", "w", newline="") as f:
    writer = csv.DictWriter(f, fieldnames=data[0].keys())
    writer.writeheader()
    writer.writerows(data)

Common Pitfalls

  • Commas in values: if a field contains commas, it must be wrapped in quotes. Most tools handle this automatically.
  • Newlines in values: multiline text fields can break CSV row detection if not properly quoted.
  • Inconsistent keys: if JSON objects have different sets of keys, the CSV will have empty cells where keys are missing.
  • Data type loss: CSV does not preserve types. The number 42 and the string "42" look identical in CSV.
  • Unicode and encoding: always use UTF-8 encoding to preserve special characters.

Conclusion

Converting between JSON and CSV is a routine task for developers, analysts, and anyone working with data. For simple conversions, a browser-based tool is the fastest option. For recurring or complex transformations, use a scripting approach. Try our free JSON to CSV and CSV to JSON converters for instant results.

Tools Mentioned in This Article