Développement

CSV vers JSON: Clean the Data Before You Convertir It

A practical checklist for headers, delimiters, quoted fields, blank rows and type assumptions before turning CSV into JSON.

Published October 6, 20268 min readBy Get Tools Lab Editorial & Engineering Team

CSV looks simple because you can open it in a spreadsheet. The file format is less simple than it appears: commas can occur inside values, line breaks can live inside quoted cells, and a column that looks numeric may actually contain identifiers that must keep their leading zeroes.

Make the header row intentional

When the first row becomes JSON property names, unclear headers become unclear data. Replace blank headers and decide how duplicates should be handled. A row like Name,Name,Date may be visually understandable in a spreadsheet but ambiguous in an object format.

Confirm the delimiter

Not every “CSV” uses commas. Exports from some regional settings use semicolons, and tab-separated data is common. If every row appears to have one giant field, the delimiter is the first thing to check.

Quoted values are normal

A value such as "Lahore, Punjab" contains a comma but should remain one field. Good CSV parsers respect quoting rules. Problems appear when quotes are unbalanced or copied from a system that uses non-standard escaping.

Decide whether types should be inferred

Automatic conversion of 00123 to the number 123 can destroy a postal code or product identifier. Dates are similarly tricky. Unless you have a schema, treating CSV cells as strings is often the least surprising starting point.

Supprimer accidental blank rows

A blank line at the end of a spreadsheet export is harmless to a person but may become an empty record depending on the parser. Scan the row count before and after conversion so you notice unexpected records.

Test a small sample first

If the file has tens of thousands of rows, copy the header plus five representative rows—including one with quotes, one blank value and one unusual character. Validate the shape on that sample before processing the full dataset.

Check the JSON, not just the success message

Look at field names, row count and at least a few values from different columns. If the JSON will feed an API, compare the output to the API’s expected schema. Conversion can be technically successful and still produce the wrong shape.

A useful mental model

CSV is a table; JSON is a data structure. Convertiring between them requires decisions about headers, types and nesting. The cleaner and more explicit the table is before conversion, the fewer surprises you will have afterward.

Prêt à essayer ?

Utilisez l'outil Get Tools Lab associé directement dans votre navigateur.

Open CSV vers JSON