DEVELOPER GUIDE

How to convert CSV to JSON without losing IDs

Parse headers, quoted commas, and multiline cells while keeping leading zeros and long identifiers as strings.

4 min read•DevToolbox editorial

Use the first row as field names

This converter uses the first CSV row as object keys. Every header must have a name and each name must be unique. Each data row needs the same number of fields, including empty fields, or the converter reports its row number.

Input:  id,name
        0012,Alex
Output: [{"id":"0012","name":"Alex"}]

Keep text values as text

CSV has no built-in number type. DevToolbox keeps every cell as a string, so a postal code such as 0012 or a long account identifier is not silently rounded or stripped of leading zeros. Convert selected fields to numbers later, only when your application knows their meaning.

Quoted fields can contain commas and newlines

Wrap a field in double quotes when it contains a comma or a line break. Write a literal quotation mark as two quotation marks inside a quoted field. A line break inside those quotes remains part of one cell, not a new record.

Input:  name,notes
        Alex,"Uses CSV, JSON"
Output: [{"name":"Alex","notes":"Uses CSV, JSON"}]

Check malformed rows before using the JSON

An unclosed quoted field, duplicate header, or row with the wrong field count is rejected. Fix the CSV source rather than guessing which column a value belongs to. The converter processes the text in your browser and lets you copy or download the result.

Put it into practice with a free tool that runs in your browser.
Open CSV to JSON