How to Convert CSV to JSON (With Examples)

Have CSV from Excel or Google Sheets but need JSON for an API or config file? This guide explains how to convert CSV to JSON safely and correctly.

Understanding CSV structure

CSV stands for Comma-Separated Values. Each line represents a row and each comma separates a column. The first row typically contains headers that describe the columns.

id,name,country
1,Avi,IN
2,Kriti,US

How CSV maps to JSON

The most common pattern is to convert each CSV row into a JSON object, using the headers as keys.

[
  { "id": 1, "name": "Avi", "country": "IN" },
  { "id": 2, "name": "Kriti", "country": "US" }
]

Using the CSV → JSON Converter

JSONViewerTool.com includes a dedicated CSV → JSON Converter page that handles parsing for you.

  1. Open CSV → JSON Converter.
  2. Paste your CSV into the left editor or upload a .csv file.
  3. Click Convert CSV → JSON.
  4. Inspect the JSON on the right in Tree or Code mode.
  5. Copy or download the JSON for your API or app.

Dealing with data types

By default, everything in CSV is a string. In JSON you may want numbers and booleans instead of strings. After conversion, you can edit types in the JSON viewer if your API expects strict types.

Use cases for CSV → JSON

  • Migrating data from spreadsheets into applications or databases.
  • Feeding data into REST APIs or bulk import endpoints.
  • Creating mock JSON data from CSV to test APIs.

Next steps

Once your CSV is converted, you can further edit and validate it in the main JSON Viewer, or convert it again using other tools like JSON → YAML.

Related articles