Converting CSV to JSON: Keeping Types, Headers and Nested Data Intact
How to turn a spreadsheet export into clean JSON for an API or app: header rules, number and boolean types, empty values, nested fields and a validation checklist.
Published October 19, 2026 · By Sudip Bhowmick
A CSV file is flat text with no types, while JSON has strings, numbers, booleans, nulls, arrays and nested objects. Converting one to the other is easy to do and easy to do badly. The tool will happily turn every value into a string, drop a leading zero, or produce keys with spaces in them. A few decisions up front give you JSON that your code can use without further cleanup.
Start With the Header Row
The first row of the CSV becomes the property names in JSON, so tidy it before converting. Names such as First Name or Order # work as keys but are awkward in code. Use consistent, predictable names: firstName for camelCase code or first_name for snake_case. The Json Key Case Converter on this site can change the style of every key afterwards if you need to.
- ▸Make sure every column has a unique, non-empty header.
- ▸Avoid duplicate headers, because later columns will overwrite earlier ones.
- ▸Remove blank trailing columns, which many spreadsheet exports add.
Types: What Becomes a Number and What Must Stay Text
CSV carries no type information, so a converter has to guess. Numbers and booleans are usually detected, which is helpful for prices and counts and harmful for identifiers.
- ▸Phone numbers, postal codes, product codes and ID numbers with leading zeros must stay strings. 007 as a number becomes 7 and the information is lost.
- ▸Very long numbers, such as card-like identifiers, can lose precision when treated as numbers, so keep them as text.
- ▸Dates have no JSON type. Keep them as ISO strings such as 2026-10-19 so every system can parse them.
- ▸Decide how to treat true, false, yes and no. If your code expects real booleans, normalize them before converting.
Empty Cells
An empty cell can mean no value, an empty string or not applicable. In JSON these are different: null, an empty string, or a missing key. Pick a rule and apply it everywhere. Most APIs prefer null or omitting the key over an empty string, because it is unambiguous.
Quotes, Commas and Line Breaks Inside Cells
A well formed CSV wraps any cell containing a comma, quote or line break in double quotes and doubles any quote inside. If your converted JSON shows shifted values or extra columns, the delimiter or quoting is the likely culprit. Some European exports use semicolons rather than commas, so check the delimiter before you convert.
Nested Data and Arrays
Flat CSV cannot express nesting directly, so teams use naming conventions such as address.city and address.country as column headers and rebuild the objects afterward. For lists, a common pattern is a delimiter inside one cell, like red|green|blue, which you split into an array in code.
If your data is deeply nested, consider whether a flat CSV is the right source at all.
Validate the Output
After converting with the CSV to JSON tool, paste the result into the JSON Formatter. It will pretty print the data and report any syntax error. Then spot check three things: the number of objects matches the number of CSV rows, a row with leading zeros kept them, and a row with empty cells produced the null or missing value you chose.
Conclusion
Good CSV to JSON conversion is mostly preparation: clean headers, deliberate types, a consistent rule for empty cells and the right delimiter. Convert, format and spot check, and you will end up with data your application can consume with no surprises.
Free Tool
Open the CSV to JSON Converter