← Back to all posts

How do CSV to JSON converters handle quotes and nested fields?

CSV quote escaping, commas and newlines inside fields, and the trade-off of flattening nested JSON objects with dots when converting to CSV — plus a recommendation for the TwoThink local converter.

When wiring up data pipelines, CSV and JSON often have to be converted into each other. The hard part is rarely "can it convert" — it is quoted fields and nested structures.

How quotes work in CSV

Following the common RFC 4180 conventions:

  • Wrap a field in double quotes when it contains a comma, a newline or a quote
  • Escape a double quote inside a field by doubling it: ""

For example "Shanghai,Pudong" is one field, not two columns. The TwoThink CSV and JSON converter parses along those rules in your browser, without uploading anything.

Converting nested JSON to CSV loses the hierarchy

CSV is essentially a two-dimensional table. If the JSON is:

[{"user":{"name":"John"},"age":25}]

the usual approach when converting to CSV is to flatten the keys into user.name. Converting back to JSON does not restore the nested object — you get flat keys instead. When you need the hierarchy, rehydrate it in your own code, or keep the JSON out of CSV altogether.

Pick the direction by hand

Guessing the direction from "does it contain a comma" is unreliable — JSON contains commas too. Choosing CSV → JSON or JSON → CSV explicitly is safer; at most, the tool will suggest a direction.

Related tools