Skip to main content

Data conversion

CSV to JSON: check types, IDs, and quoted fields

Convert a small CSV example, check quoted commas and inferred types, and recognize when IDs or multiline fields need a different import method.

Published by qwertywelch.com

A successful conversion needs more than valid JSON. A customer ID of 00127 must still identify the same customer, a comma inside a description must stay inside that description, and a missing value must have the meaning your receiving application expects.

Use this walkthrough for a small, inspectable table. The converter infers numbers, booleans, and null values automatically. That is convenient for quantities, but it cannot preserve every CSV value exactly. Keep the original export while checking the result.

Set the delimiter and header row first

Choose the delimiter used between fields: comma, semicolon, tab, or pipe. A comma appearing inside a quoted field is data. For example, a description of Blue, large occupies one column when the complete description is enclosed in double quotes.

Enable First row as headers when the first row contains field names. Give every column a unique, nonempty name before conversion. If the file has no header, disable the option; this converter creates names such as col0 and col1. Check the first data row afterward so you do not accidentally discard it as a header.

Convert a table with commas and quotation marks

This sample deliberately uses a letter-prefixed SKU, which remains text, and a quantity, which becomes a number. CSV represents a quotation mark inside a quoted field by doubling it. JSON represents that same quotation mark with a backslash escape. The different output syntax preserves the description's meaning.

  1. Open CSV to JSON, select comma, and enable First row as headers.
  2. Enable pretty printing with two-space indentation, then paste the input and convert.
  3. Confirm one data row and three columns. Compare each property with the output below before copying or downloading.
One inventory record, with a quoted comma and an embedded quotation mark

Input

sku,quantity,description
A-00127,12,"Blue, size ""large"""

Expected result

[
  {
    "sku": "A-00127",
    "quantity": 12,
    "description": "Blue, size \"large\""
  }
]

Check identifiers before accepting inferred types

This converter changes 00127 into the number 127, including when the CSV field is written as "00127". CSV quotation marks protect separators; they do not instruct this tool to preserve a string type. Large numeric identifiers can also lose precision when converted to JavaScript numbers.

Empty fields and the word null become JSON null. True and false become booleans without regard to capitalization. Leading and trailing field whitespace is trimmed. If an empty string, the literal text "null", or exact spacing matters, the generated value requires review.

For a tiny table, compare every affected cell against the original and edit the JSON to use strings such as "00127". Adding quotation marks around 127 afterward cannot recover the missing zeros. For a real dataset, use an import process that explicitly keeps identifier columns as strings rather than repairing rows manually.

Know which CSV inputs need another parser

CSV can contain a line break inside a quoted field. The current converter splits input into lines before reading fields, so it does not correctly handle those multiline records. Use a CSV parser with quoted multiline support for exports containing addresses, notes, or descriptions with embedded newlines.

Also check uneven rows and duplicate headers. Extra values beyond the header width are omitted, missing values become null, and repeated header names can overwrite earlier values. A plausible-looking output is not evidence that the entire table survived.

For a local scripted import, Python's csv module provides a starting point: open the file with newline='', select the correct delimiter, and use csv.DictReader without automatic numeric conversion. Validate unique headers and consistent row widths separately, then convert only the quantity or other columns whose schema requires numbers.

Verify meaning as well as syntax

Before passing the JSON to an application, inspect a normal row, a row with punctuation, and every row with a special identifier or missing value. Keep a short expected-field list beside the output. This catches omissions that a JSON syntax checker cannot detect.

  • Count records, excluding the CSV header, and compare the count with the JSON array length.
  • Confirm property names match the receiving application's schema exactly.
  • Check identifier length, leading zeros, and the distinction between strings, numbers, empty strings, and null.
  • Check quoted descriptions against the original text, then parse the final JSON in the receiving application before using the complete dataset.

Try the tools

Start with the sample above. Keep an unchanged copy of your own data before converting it.

References and corrections

Found a result that differs from this guide? Send a correction with a small, non-sensitive example and your expected result.

More practical guides