Why turn a spreadsheet into JSON
CSV is what spreadsheets, CRMs, banks and analytics dashboards export. JSON is what web APIs, JavaScript code, NoSQL databases and most configuration systems consume. The conversion comes up constantly: seeding a test database from a sheet a colleague maintains, turning a product list into fixtures for a front-end prototype, feeding a list of redirects or translations into a build script, or posting a batch of records to an API that only accepts JSON.
The output here is a JSON array with one object per data row. The header row supplies the property names, so a sheet with columns sku, title and price becomes objects with exactly those three keys, ready to loop over.
How the parser reads your CSV
CSV looks trivial until a value contains the separator. The parser follows the rules of RFC 4180, the closest thing CSV has to a standard:
- A field wrapped in double quotes may contain the delimiter, line breaks and quotes.
"Smith, John"stays one value. - A quote inside a quoted field is written twice:
"6"" pipe"becomes6" pipe. - Lines may end with Windows-style CRLF or Unix-style LF; both are handled.
- A byte order mark at the start, which Excel adds when saving as CSV UTF-8, is removed so it does not end up glued to the first column name.
- Completely empty lines are skipped.
The delimiter is chosen by counting commas, semicolons, tabs and pipes in the first line and picking the most frequent. That works for almost every export, but it relies on the header being representative. If your header is a single column with no separators, the comma is assumed.
Spaces around header names are trimmed, so price becomes the key price. Values in the data rows are kept exactly as written, including any leading or trailing spaces.
Typed values versus strings
With "Detect numbers and booleans" switched on, each cell is checked against a short list of rules:
- Plain integers and decimals such as
42,-7and19.99become JSON numbers, as long as they have at most 15 digits. - Exactly
trueandfalse, in lower case, become booleans.TRUE,Yesor1stay as they are. - An empty cell becomes
null. - Everything else, including longer digit strings,
1.5e3,+5,.5,1,234and dates, stays a string.
This is convenient for most data, but numbers in JSON carry no formatting, so some values change meaning when typed:
- Leading zeros disappear. A US ZIP code
02134becomes2134, and an article number007becomes7. - Long digit strings would lose precision. JavaScript numbers are exact only to about 15 significant digits, so values with more digits, such as a 20-digit order ID or a card number, are kept as strings instead of being rounded.
- Phone numbers without a plus sign or spaces become numbers too.
If any column holds identifiers rather than quantities, switch the option off and convert the few genuinely numeric fields in your own code. With the option off, empty cells become empty strings instead of null.
When the output looks wrong
- Everything lands in one key. The delimiter was not detected, usually because the header has a different separator from the data, or no separator at all. Check the first line.
- Values are shifted by one column. A field contains the delimiter but is not quoted. Re-export from the source application rather than editing by hand; spreadsheets quote such fields automatically.
- Extra columns vanish. Keys come only from the header, so cells beyond the last header column are dropped. Rows with fewer cells get
nullor an empty string for the missing ones. - Two columns, one key. If the header repeats a name, the later column overwrites the earlier one in every object. Rename one of them first.
- Strange characters such as é. The file was saved in a legacy encoding. Save it again as CSV UTF-8 and paste it once more.
Working with the result
The JSON is printed with 2-space indentation, which is fine for reading and for committing to a repository. To minify it for an API request or reindent it, run it through the JSON formatter. To go back the other way after editing, JSON to CSV rebuilds a sheet from the array. The conversion runs entirely in the page, which matters when the export contains customer names, emails or salaries.