Converting between JSON and CSV
JSON and CSV are the two most common data interchange formats, each with distinct strengths. JSON (JavaScript Object Notation) supports nested structures, mixed types, and is the default format for web APIs. CSV (Comma-Separated Values) is flat, tabular, and universally supported by spreadsheets, databases, and data analysis tools.
Converting from JSON to CSV requires flattening: every JSON object in the array becomes a row, and every unique key across all objects becomes a column header. Objects with missing keys get empty cells. The reverse — CSV to JSON — maps each row to an object using the header row as property names.
The main challenge is handling mismatched schemas. In JSON, objects in the same array can have different keys. This tool unions all keys across all objects to produce a complete set of columns, filling in blanks where needed.
Handling nested JSON
CSV is inherently flat — it has rows and columns, nothing more. When JSON contains nested objects (like {"user": {"name": "Alice", "email": "a@b.com"}}), you need a flattening strategy.
Dot notation is the most common approach: user.name and user.email become column headers. It preserves the hierarchy in the column name, making it possible to reconstruct the original structure later. This tool uses dot-notation flattening by default.
For deeply nested data or arrays within objects, consider whether CSV is the right output format. Sometimes it's better to restructure or denormalise the JSON first, or to extract only the fields you need into a flat structure before converting.