Developer Tools

CSV to JSON: Convert Tabular Data the Right Way

Convert CSV to JSON without losing data: header mapping, type inference, quoting rules and nested records, with a clear before-and-after example.

2 min read·Updated 2026-07-31

CSV and JSON represent the same information in very different ways: rows and columns versus nested objects. Converting between them is easy to get subtly wrong — every value arrives as a string, quoted commas break naive parsers, and a single blank cell can shift an entire record. This guide shows how to map CSV into JSON correctly and how to round-trip the result back again.

The header row is your schema

The first CSV line becomes the key names for every object. Whatever the header says, that is what your JSON keys will be, including typos and spaces:

Name,Age,City
Ada Lovelace,36,London
Grace Hopper,85,Arlington

produces [{"Name":"Ada Lovelace","Age":"36","City":"London"}, ...]. Clean the header before converting:

  • Replace spaces and dashes with underscores so keys stay identifier-safe.
  • Normalise casing, otherwise "Product ID" and "productId" become two different fields.
  • Delete duplicates — a repeated header silently overwrites earlier values.
  • Trim stray whitespace; invisible spaces in keys cause bugs that take hours to find.

Numbers, booleans and empty cells

By default everything from CSV is a string. Decide deliberately which columns should be coerced:

CSV cellAs stringTyped
36"36"36
12.50"12.50"12.5
true"true"true
(empty)""null

Keep identifiers such as 00712 and phone numbers as strings — numeric conversion silently drops leading zeros. Quantities, prices and flags should become real numbers and booleans so downstream code does not compare text.

Quoting, commas and embedded newlines

CSV only has one escape rule: a field containing a comma, a quote or a line break must be wrapped in double quotes, with internal quotes doubled:

"Smith, Ada","She said ""hello""",36

A parser that splits lines on commas will shred this record. Always use a real CSV parser; the CSV to JSON Converter handles quoted fields, escaped quotes and multi-line cells correctly.

Going flat to nested

Repeated columns are a signal to nest. Columns named address.city or tags (pipe-separated) can be reshaped into objects and arrays:

{"name":"Ada","address":{"city":"London"},"tags":["math","code"]}

Flattened dotted keys are the common alternative — pick one convention per project and document it, because JSON offers no built-in hint about which shape you intended.

Before and after

id,product,price
1,"Widget, large",9.99
2,"Gadget",4.50

becomes:

[{"id":1,"product":"Widget, large","price":9.99},
{"id":2,"product":"Gadget","price":4.5}]

Going back is symmetric — the JSON to CSV Converter takes the first object's keys as the header and flattens nested values with the same dotted convention.

Frequently asked questions

Should IDs stay strings or become numbers? If they have leading zeros, contain letters or exceed safe integer range, keep them as strings. Otherwise numbers are fine.

Why did my dates turn into plain text? JSON has no date type, so dates arrive as strings (or as epoch numbers). Parse them in your application, not during conversion.

How do I convert thousands of rows? Stream the file rather than loading it whole, or split it first — the tools here handle typical exports of up to a few megabytes comfortably.

Tools used in this guide

Related guides