← Back to Articles

JSON to CSV Conversion: Mapping Complex Data to Tabular Format

Published February 8, 2026

Why Convert JSON to CSV?

JSON and CSV serve different purposes. JSON is powerful for complex, nested data suitable for APIs and applications. CSV excels in spreadsheets—Excel users can't read JSON natively, but they understand CSV instantly. Converting JSON to CSV enables:

  • Exporting API data for spreadsheet analysis
  • Preparing data for non-technical stakeholders
  • Importing into business intelligence tools
  • Creating importable files for bulk operations
  • Archiving data in human-readable format

The Fundamental Challenge: JSON is Hierarchical, CSV is Flat

This is the core problem. Consider customer data with addresses:

JSON (Nested)

{ "id": 1, "name": "John Doe", "email": "john@example.com", "address": { "street": "123 Main", "city": "Springfield", "zip": "62701" }, "orders": [ { "id": 101, "total": 49.99 }, { "id": 102, "total": 129.98 } ] }

CSV (Flat)

id,name,email,address_street,address_city,address_zip 1,John Doe,john@example.com,123 Main,Springfield,62701

But what about the orders? Can't be in one row!

The customer has one record but two orders. One row in CSV can't represent multiple order values. How do we handle this?

Flattening Strategies

Strategy 1: Dot Notation (Nested Flattening)

Flatten nested objects using dots in column names:

id,name,email,address.street,address.city,address.zip 1,John Doe,john@example.com,123 Main,Springfield,62701

Pros: Preserves hierarchical structure in column names. Easy to read.

Cons: Doesn't handle arrays. Still one row per customer, losing order data.

Strategy 2: Array Expansion (Multiple Rows)

Create one row per array element, repeating parent data:

customer_id,customer_name,email,order_id,order_total 1,John Doe,john@example.com,101,49.99 1,John Doe,john@example.com,102,129.98

Pros: Preserves all data. Works for systems expecting CSV from relational databases (normalized form).

Cons: Repeats customer data. Denormalized. Risk of data inconsistency if customer info changes.

Strategy 3: JSON Array in Cell

Keep arrays as serialized JSON strings within CSV cells:

id,name,email,address_street,orders 1,John Doe,john@example.com,123 Main,"[{""id"":101,""total"":49.99},{""id"":102,""total"":129.98}]"

Pros: Preserves all data without repetition. Maintains structure.

Cons: Spreadsheets can't display/edit the JSON array nicely. Not human-friendly.

Strategy 4: Separate Files

Create multiple CSV files with foreign key relationships:

customers.csv:

id,name,email 1,John Doe,john@example.com

orders.csv:

id,customer_id,total 101,1,49.99 102,1,129.98

Pros: Normalized, no duplication. Mirrors relational database structure. Most professionally correct.

Cons: Multiple files to manage. Requires understanding of relationships.

Choosing Your Strategy

Use Dot Notation When:

  • JSON has simple nested objects but no arrays
  • Readers will use spreadsheets and don't need to edit nested values
  • One-to-one relationships (customer → address)

Use Array Expansion When:

  • Target system expects normalized, relational data
  • Data volume is manageable (no massive repetition)
  • Analysis will use SQL-like grouping and aggregation

Use JSON in Cells When:

  • Data will be re-imported into JSON-aware systems
  • Human editing of nested data isn't required
  • Preserving exact structure takes priority

Use Multiple Files When:

  • Sharing data with non-technical users (business professionals)
  • Data complexity warrants proper normalization
  • Each entity type needs independent analysis

Handling Edge Cases

⚠️ Null and Empty Values

JSON distinguishes between null (no value), empty string (""), and missing property. CSV doesn't.

JSON: { "phone": null, "note": "", "email": undefined }

Strategy: Decide upfront: treat all as empty cells, or use markers like "NULL" for null values. Document your choice.

⚠️ Empty Arrays

Customer has zero orders. Using array expansion strategy: should they appear in CSV?

Strategy: Include customers with empty arrays (one row with order fields empty). This preserves the complete customer list.

⚠️ Inconsistent Structures

Some records have address, others don't. Some orders have tracking_number, others don't.

Strategy: Create columns for all possible properties across all records. Use empty/null values for missing data.

⚠️ Special Characters

Commas, quotes, and newlines in data need proper quoting when converting to CSV.

Strategy: Use a conversion tool that handles quoting/escaping automatically, like SmartJson's JSON-to-CSV converter

⚠️ Large Numbers and Precision

JSON supports arbitrary precision numbers. Excel and CSV treat large numbers as floating-point, losing precision.

Strategy: For financial data, represent amounts as strings or document the precision loss.

Data Type Preservation

JSON has explicit types: numbers, strings, booleans. CSV has no type information—everything is a string until the reader interprets it.

Problem: JSON: "id": 12345 becomes CSV cell 12345. Excel auto-detects as number (fine). But "zip": "02134" becomes CSV 02134. Excel strips leading zero, becoming 2134.

Solution: Quote all string values in CSV, even if they look numeric. "02134" preserves the leading zero when reimported.

Best Practices for Conversion

1. Understand Your Data First

Look at your JSON structure. Are there nested objects? Arrays? Inconsistencies? Your strategy depends on complexity.

2. Define Your Goals

Who is consuming this CSV? Business analysts need simple flattening. Data engineers need relationally-normalized data.

3. Document Mapping Rules

"address.street" in headers isn't obvious to spreadsheet users. Include a data dictionary.

4. Test with Target Application

Will Excel open it correctly? Does the import tool handle your quoting? Test before deploying.

5. Use Automated Tools

Don't manually convert—use SmartJson's JSON-to-CSV converter which handles quoting, escaping, and type preservation automatically.

Key Takeaways

  • JSON-to-CSV conversion is lossy—hierarchical data flattens into a table
  • Choose flattening strategy based on data complexity: dot notation for simple nested objects, array expansion for multiple rows
  • Separate files are the most professionally correct approach for complex data
  • Consistent CSV structure requires handling missing fields and null values
  • Always quote string-looking values (ZIP codes, IDs) to preserve them
  • Test conversions with actual target applications before deployment