Mastering RFC 8259 JSON Validation & RFC 4180 CSV Escaping
Why trailing commas break strict JSON parsers, and how to flatten deeply nested API objects into spreadsheet-ready CSV rows without corrupting commas or quotes.
JavaScript Object Notation (RFC 8259) is intentionally stricter than JavaScript object literals. Every property key must be wrapped in double quotes, strings cannot contain raw unescaped newline characters, and trailing commas after the final element of an object or array are syntax errors.
When converting JSON arrays into Comma-Separated Values (RFC 4180), three edge cases frequently break naive string-join scripts: fields containing commas, fields containing double quotes, and fields containing multiline breaks. To remain compliant, any field containing those characters must be enclosed in double quotes, and any literal double quote inside the field must be escaped by doubling it ("").
For hierarchical objects (such as user.address.city), flattening nested keys using dot notation and scanning the entire array to compute the union of all property keys ensures sparse fields align under the correct column header.