Convert CSV to JSON without uploading your data

Practical guide · Windows 10 and Windows 11

Somebody hands you a CSV and you need it as JSON to load into an application, feed an API or run a test. Excel will not do it. The first result on Google is an online converter asking you to drag the file in, and that is where it is worth pausing for a second.

What tends to live inside a CSV: customer lists, orders, payroll, email addresses, medical records, price inventories. Uploading that file to a free service is handing it to a third party. If your organisation has any data-protection obligation at all, that upload is precisely the thing you cannot do, however fast it is.

There are three ways to convert it without the file leaving your machine.

1. PowerShell, which you already have

Two commands chained together and you are done:

Import-Csv data.csv | ConvertTo-Json | Out-File data.json -Encoding utf8

And in the other direction:

Get-Content data.json | ConvertFrom-Json | Export-Csv data.csv -NoTypeInformation -Encoding utf8

If your CSV uses semicolons as the separator, which is normal for files exported from Excel in most of Europe, pass the delimiter:

Import-Csv data.csv -Delimiter ';' | ConvertTo-Json | Out-File data.json -Encoding utf8

What it cannot do: it struggles with nested or very large files, and by default ConvertTo-Json only descends two levels (widen it with -Depth 10). It also will not warn you if the CSV was malformed: it hands back a JSON with the fields shifted and you find out much later.

2. Python, if you already have it

Three lines, and full control over types and encoding:

import csv, json; json.dump(list(csv.DictReader(open('data.csv', encoding='utf-8-sig'))), open('data.json','w',encoding='utf-8'), ensure_ascii=False, indent=2)

That utf-8-sig is not a minor detail: it swallows the invisible marker Excel writes at the start of its files, which otherwise turns the name of your first column into something like Name.

What it cannot do: it needs Python installed, which does not ship with Windows.

3. A local tool, for several files

If it is many files, or you want to rename them in the same pass, TandaFiles converts between CSV, TSV, JSON, TXT and Markdown in the browser, uploading nothing:

  1. Open folder or Add files.
  2. Under Format conversion, tick convert and choose JSON.
  3. Apply, and it hands the converted files back.

It respects quoting and detects the separator, which is exactly where homemade conversions fall over. And because everything runs on your own processor, the customer file stays where it is.

The three details that break a conversion

The separator. "CSV" means comma-separated values, but Excel on a European regional setting exports with semicolons, because the comma is the decimal mark. Open the file with the wrong separator and everything lands in a single column.

The quoting. A field containing a comma is written in quotes: "García, Ana". If the converter does not understand quoting, it splits that field in two and shifts the whole row from there on. It is the most treacherous failure, because the resulting file looks correct until you go looking for a specific value.

The encoding. If opening the JSON shows you José where it should say José, the file was read as Windows-1252 and written as UTF-8, or the other way round. That is why -Encoding utf8 appears in every command above.

Which one to use

Try TandaFiles free in your browser