Yueseryueser.com

← All guides

CSV to JSON Guide: Headers, Quotes, and the Hierarchy You Lose

CSV expresses rows and columns. JSON expresses nesting. Converting from CSV can only give you flat objects; expecting it to rebuild a hierarchy is the wrong starting point.

Open the tool:CSV to JSON

Getting the spreadsheet into code

A product manager exports a config sheet, and you want JSON the frontend can consume. A test needs a batch of row-shaped data. An API doc needs a mapping table. In each case, clean up the header first, then convert once.

The result is predictable: the first row becomes keys, and every following row becomes one object. That suits dictionaries, allow-lists, and records where one row equals one entry — not parent-child relationships.

Quotes, commas, and headers

With comma separation, a field that contains a comma must be wrapped in double quotes, like a city and country pair. A double quote inside a field is written as two double quotes. Without quoting, the row splits into extra columns and every field after it shifts, silently.

Headers become JSON keys, so prefer lowercase ASCII with underscores. Spaces and punctuation force bracket notation in code. Duplicate headers let later columns overwrite earlier ones, and rows shorter than the header get empty strings for the missing fields.

Boundary: all strings, no hierarchy

Every value stays a string: a numeric-looking field is not a number, a boolean-looking field is not a boolean, and an empty cell is an empty string rather than null. Convert types explicitly in code, because a wrong guess becomes an implicit bug everywhere.

CSV has no nesting. Representing a parent-child object means flattening it to a dotted key, and the JSON you get is still flat. This tool also parses line by line, so a quoted field containing a newline breaks, and semicolon-separated files are not supported.

FAQ

Why is every number a string?

The tool does not infer types, deliberately. Zero-padded IDs, very long numbers, and boolean-looking fields are easy to corrupt with automatic conversion. Convert in code and handle the failures.

What if a field contains a comma?

Wrap the whole field in double quotes, for example a city followed by a country inside one pair of quotes. If the file is semicolon-separated, this tool will not read it; export as comma-separated instead.

Can it handle nesting or multi-line cells?

No. CSV output is always flat, so nesting has to be assembled afterwards. A newline inside quotes breaks row parsing. For either case, consider working with JSON or importing the spreadsheet directly.

Related tool:CSV to JSON