CSV and JSON are the two most common data formats in modern software, and they're constantly in tension. Spreadsheets and data exports come in CSV. APIs, config files, and NoSQL databases want JSON. Converting between them is a routine task — but doing it right means choosing the correct output format for your use case.
Why Convert CSV to JSON?
The most common reasons to convert CSV to JSON are:
- An API endpoint expects a JSON body, but your data lives in a spreadsheet
- A config file or seed file for an application needs to be in JSON format
- A NoSQL database (MongoDB, Firestore, DynamoDB) ingests JSON documents
- A front-end application reads a JSON file as a data source
- You're writing automated tests that need JSON fixtures from real data
The Three JSON Output Formats
Array of Objects (most common) — Each row becomes a JSON object where the column headers are keys. A CSV row of Alice, alice@example.com becomes {"name": "Alice", "email": "alice@example.com"}. This is what most APIs and applications expect.
Array of Arrays — Each row becomes a plain array, with the first array being the headers. More compact but less readable. Useful when you're optimizing for file size or the consuming system doesn't need named keys.
Nested by Key — When your first column is an identifier, you can nest all other fields under that key, producing a dictionary-style object. A customer ID becomes the top-level key, and all customer attributes nest beneath it. Useful for lookup tables.
Upload your CSV and see exactly what's wrong — Sohovi profiles quality in seconds — try Sohovi free.
How to Convert CSV to JSON
Browser-based tool: Upload your CSV and select your output format. The conversion happens locally — your data stays in your browser. Best for one-off conversions, non-technical users, and sensitive data.
Python: The standard library's csv module reads CSV rows into dictionaries, and json.dumps() serializes them to JSON. pandas can do the same in two lines with read_csv() and to_json(). Both approaches are easy to wrap in a script for batch processing.
JavaScript: The FileReader API reads the file, and a simple split on newlines and commas produces the array of objects. Libraries like papaparse handle edge cases (quoted commas, multi-line fields) automatically.
Common Gotchas
Watch for encoding issues — CSVs from Windows systems often use Windows-1252 encoding, not UTF-8. Open the file specifying the encoding explicitly to avoid garbled characters. Also watch for empty cells: decide in advance whether they should become null, empty string, or be omitted from the JSON object.
For validating the quality of your source CSV before conversion — checking completeness, format consistency, and duplicates — Sohovi profiles your file across all dimensions in your browser before you convert.
Sohovi automatically finds every duplicate in your dataset — including near-matches — and shows you exactly which rows are affected.
Keep Reading
Try the Free CSV to JSON Converter →