devShakib

Loading devShakib…

JSON / CSV

Convert a JSON array of objects to CSV and back, with quote-aware parsing.

CSV looks like the simplest format in computing and is one of the fussiest. A field containing a comma has to be quoted, a quote inside a quoted field has to be doubled, and a value containing a newline is legal but breaks every tool that reads the file line by line. Quote-aware parsing is the difference between converting a file and corrupting it.

Going from JSON to CSV also forces a shape decision that JSON did not require. CSV is strictly rectangular, so every object needs the same columns; nested objects and arrays have no natural representation and must be flattened or dropped. If your records vary in shape, expect empty cells where the format is telling you the two things do not really fit.