Guide
Parsing CSV into structured JSON
By Logappradeep · ServiceNow developer
CSV looks simple, but it has no formal type system and only a loose standard (RFC 4180). Converting it to JSON gives each row a clear structure that JavaScript, APIs, and NoSQL databases can work with directly. This converter treats the first row as the header and turns every following row into an object whose keys are the column names.
A quick example
name,age,city
Ada,36,London
"Hopper, Grace",85,"New York"
becomes:
[
{ "name": "Ada", "age": "36", "city": "London" },
{ "name": "Hopper, Grace", "age": "85", "city": "New York" }
]
Notice that "Hopper, Grace" stays one field: commas inside double quotes are part of the value, not separators. Quoted fields may also contain line breaks and doubled quotes ("") that represent a literal quote character. Blank lines are skipped, and the delimiter is detected automatically, so semicolon- and tab-separated exports also work.
Strings or typed values?
CSV cannot mark 36 as a number or true as a boolean, so by default every value stays a string. Tick Convert numbers & booleans to have numeric-looking values become JSON numbers and true/false become booleans. That is convenient for clean numeric data, but be careful with identifiers: a ZIP code like 02134 or a product code like 007 loses its leading zeros. Leave the option off for columns like these and convert types in your own code.
Errors you are likely to hit
- Field count mismatches. A row with fewer or more fields than the header triggers an error such as "Too few fields", along with the row number. The usual causes are a stray unquoted comma or an unclosed quote that swallows the next line.
- Duplicate or blank headers. Two columns with the same name cannot both be keys in one object. Give every column a unique, non-empty name before converting.
- A hidden byte order mark. Files saved as "UTF-8 with BOM" start with an invisible character that can end up glued to the first header name. If the first key looks right but lookups fail, this is the likely cause.
- Empty cells become empty strings rather than
null. Decide in your code whether an empty value means "missing".
Where this is useful
Seeding a database or mock API from a spreadsheet, turning an analytics export into fixtures for tests, converting a product list for a JSON-based CMS, and inspecting a CSV file's structure when an import job rejects it. A column named address.city stays a flat key with a dot in it; reshape it in code if you need nested objects.
Parsing happens live in your browser, so spreadsheet data stays on your computer.