How to convert CSV to JSON without uploading your file
Customer lists, exports and spreadsheets often should not be uploaded to a random website. You do not need to.
In your browser, nothing uploaded
Modern browsers can read a file you pick and process it locally. Tooltern's converter does exactly that: the file never leaves your computer, there is no account and no log. It detects the delimiter, keeps tricky values safe and shows a table preview before you download the JSON. You can check for yourself by turning off your Wi-Fi after the page has loaded: it still works.
On the command line
If Python is installed, this turns a CSV with a header row into a JSON array of objects:
python3 -c "import csv,json,sys; print(json.dumps(list(csv.DictReader(sys.stdin)), indent=2))" < people.csv > people.jsonEvery value stays a string, which is the safe default. If you have jq or Miller, mlr --icsv --ojson cat people.csv does the same with type guessing.
Traps to watch for
- Semicolons, not commas. Excel in many European locales saves "CSV" with
;because the comma is the decimal separator. A converter that assumes commas will give you one giant column. Tooltern checks comma, semicolon, tab and pipe and picks the one that gives every row the same number of columns. - Leading zeros. Postcodes, phone numbers and product codes like
007turn into7if they are converted to numbers. Keep them as text. - Huge numbers. JSON numbers in JavaScript are only exact up to 9,007,199,254,740,991. Longer IDs (order numbers, social media IDs) get silently rounded, so they should stay strings too.
- The invisible BOM. Files saved as "UTF-8 with BOM" start with three hidden bytes that end up glued to your first column name, so
idbecomes\ufeffidand lookups fail. - Line breaks inside quotes. A quoted cell can contain a newline. Splitting the file by lines breaks those rows; a real CSV parser (RFC 4180) handles them.
- Going back. When you turn JSON into CSV for a spreadsheet, a cell that starts with
=,+,-or@can run as a formula when opened. Prefixing those with an apostrophe defuses it; the converter has a switch for this.
Questions
Is it safe to convert a CSV online?
It depends on whether the site uploads your file. A converter that works in your browser, like this one, never sends the data anywhere; one that processes it on a server can see and keep everything in it.
How do I keep leading zeros when converting CSV to JSON?
Do not convert those columns to numbers. Tooltern's type inference already keeps values like 007 or 01234 as text, and you can turn type guessing off entirely.
Why is my CSV all in one column?
It probably uses semicolons or tabs instead of commas. Pick the delimiter, or let the converter detect it.
Published .