PrivateCSV

Convert CSV to JSON

Turn CSV rows into JSON objects or JSON Lines, typed safely.

CSV file

  • Nothing is uploaded
  • Free
  • No sign-up

Guide

CSV to JSON: the complete guide

Last updated 3 min read

About this tool

PrivateCSV converts a CSV file into JSON: an array of objects whose keys come from the header row, or JSON Lines with one object per line. Plain numbers and true/false become JSON numbers and booleans while values like 02134 stay strings, and columns such as address.city can be turned into nested objects. The file is streamed, so large CSVs work, and it never leaves your browser.

How to check that your file is never uploaded

How to convert CSV to JSON

  1. Choose the CSV file. The delimiter is detected automatically.
  2. Pick the output: a JSON array, or JSON Lines with one object per line.
  3. Set the options: detect numbers and true/false, nest columns with dots, pretty-print.
  4. Click Convert to JSON and download the file.

Example

JSON Lines output with nesting on; 02134 keeps its leading zero as a string.

users.csv
id,name,zip,active,address.city
1,Ana,02134,true,Lisbon
2,Ben,02139,false,Paris
users.jsonl
{"id":1,"name":"Ana","zip":"02134","active":true,"address":{"city":"Lisbon"}}
{"id":2,"name":"Ben","zip":"02139","active":false,"address":{"city":"Paris"}}

When you need it

Feeding an API or a web app
Spreadsheets and databases export CSV; APIs, JavaScript apps and document databases such as MongoDB work with JSON. Converting with typed values saves writing and testing a parser.
Loading data tools that read JSON Lines
BigQuery, mongoimport and many log and analytics tools read newline-delimited JSON, one record per line, which can be processed without loading the whole file.
Test data and configuration
Keep fixtures or settings in a spreadsheet that anyone can edit, export CSV, and turn it into the JSON your code loads.

How values are typed

  • With detection on, values such as 42 and -3.5 become numbers, and true/false in any case become booleans.
  • Anything that would change if converted stays a string: 02134, IDs with more than 15 significant digits (a JavaScript number cannot hold them exactly), 1e5 and 1,5.
  • Empty cells become empty strings.
  • With detection off, every value is a string, exactly as in the CSV.

Keys and nesting

Each header becomes a key. Empty headers become column1, column2 and so on, duplicates get a suffix (id, id_2), and cells beyond the header get generated keys instead of being dropped.

With nesting on, address.city and address.zip become {"address": {"city": ..., "zip": ...}}. A column stays flat when nesting it would collide with another, such as address next to address.city. This is the reverse of the flattening done by the JSON to CSV converter.

Limits to know about

  • Detection works value by value, so a column can mix numbers and strings, such as 75001 and 02134. Turn detection off if every value in a column must have the same type.
  • Dates stay strings, exactly as written.
  • Without a header row each row becomes an array, and nesting is not available.
  • The output is built in your browser's memory as the CSV streams in, so very large files depend on the memory of your device.

Frequently asked questions

How do I convert a CSV file to JSON?

Choose the file, pick JSON array or JSON Lines, and click Convert to JSON. Each row becomes an object whose keys are the column names.

Should I choose a JSON array or JSON Lines?

A JSON array is a single document, which is what most programs and APIs expect. JSON Lines puts one object on each line, so it can be read line by line without loading everything, which suits large datasets, logs, BigQuery and mongoimport.

Why is 02134 a string and not a number?

A JSON number cannot start with a zero, so converting 02134 would turn it into 2134 and change the value. IDs longer than 15 digits stay strings for the same reason.

Can it create nested JSON from a CSV?

Yes. Tick “Nest columns with dots” and columns named like address.city become nested objects. Columns without dots are unaffected.

How do I convert CSV to JSON in Python?

With pandas: pd.read_csv("in.csv", dtype=str).to_json("out.json", orient="records"). dtype=str keeps every value as text; without it pandas infers types and drops leading zeros.

Related tools

Go further

Your files never leave your device

PrivateCSV runs every tool inside your browser. No upload, no account, nothing to install.