RFC 4180 Tabular Data Flattening & Escape Formulations
Converting hierarchical tree structures into 2D relational matrices requires recursive key path projection and escape handling:
1. Recursive Dot-Notation Key Path Projection
Path(O, K) = K_1.K_2 \dots K_n \implies Value(O[K_1][K_2]\dots[K_n])
2. RFC 4180 Quote Escaping Rule
Cell(v) =
" + replace(v, '"', '""') + "if v contains [d, ", \n]
Step-by-Step JSON to CSV Transformation Breakdown
Step 1: Schema Discovery & Header Aggregation
Iterate across all record objects to form universal union set U = ⋃ Keys(Ri).
Step 2: Recursive Object Unrolling
Convert
{ user: { name: "Alice" } } to user.name = "Alice".Step 3: Delimiter Serialization
Output=RFC 4180 Compliant 2D Delimited File
JSON vs CSV Representation Comparison
| Feature | JSON Format | CSV Format | Recommended Use Case |
|---|---|---|---|
| Hierarchy | Arbitrarily nested trees & lists | Flat 2-dimensional grid | Use CSV for Excel / SQL ingestion |
| File Overhead | Repeats keys for every record | Header declared once (~60% smaller) | Use CSV for large tabular exports |
| Type System | Typed (numbers, booleans, null) | Untyped text strings | Use JSON for REST API contracts |