CSV to JSON / JSON to CSV Converter
Convert between CSV and JSON. Paste CSV and click "To JSON", or paste a JSON array of objects and click "To CSV". Quoted fields containing commas, quotes, and newlines are handled correctly. Everything runs in your browser.
How the conversion works
CSV to JSON treats the first row as the field names and produces one object per remaining row.
JSON to CSV expects an array of flat objects. The header row is the union of every object's keys in the order they first appear, so objects with differing fields still produce a consistent table. Missing fields become empty cells rather than errors.
That union behaviour matters in practice. Real API exports frequently contain optional fields present in some records and absent in others. Requiring identical keys everywhere would reject such data outright.
Why CSV parsing is harder than splitting on commas
CSV looks trivial until a field contains a comma. The convention, defined in RFC 4180, is to wrap such fields in double quotes:
name,address Alice,"Main Street 5, Berlin"
Three rules follow from that:
- A quoted field may contain commas, which do not separate fields.
- A quoted field may contain newlines, so one record can span several physical lines.
- A literal double quote inside a quoted field is written
twice:
"She said ""hi"""holds the textShe said "hi".
This is why line.split(',') fails on real data. This
converter uses a state machine that tracks whether it is inside a quoted
field, which handles all three cases.
Examples
| CSV | JSON |
|---|---|
name,age |
[{"name":"Alice","age":"30"}] |
name,city |
[{"name":"Alice","city":"Berlin, DE"}] |
quote |
[{"quote":"She said \"hi\""}] |
Practical notes
Everything becomes a string
CSV has no type information. The value 30 in a CSV file is
the two characters "3" and "0", not a number, so CSV to JSON produces
"30" rather than 30. Guessing types would be worse:
a leading-zero product code like 007 would silently become
7, and a version string like 1.10 would become
1.1. Convert types deliberately after import.
Nested JSON does not fit CSV
CSV is flat by nature. An object containing another object or an array has
no natural row representation. Flatten nested structures first, for instance
turning {"user":{"city":"Berlin"}} into a
user.city column, before converting.
Delimiters differ by locale
Comma-separated is the English-language convention. In locales where the comma is the decimal separator, including German, Excel exports semicolon-separated files while still calling them CSV. If a file opens as a single column, the delimiter is likely the cause.
Excel and leading zeros
Opening a CSV in Excel can silently mangle data: leading zeros are stripped from postal codes and product IDs, and strings resembling dates are converted. Import through the text import wizard with columns marked as text, rather than double-clicking the file, when the exact values matter.
Character encoding
CSV carries no encoding declaration. UTF-8 is the sensible default, but Excel on Windows may interpret a UTF-8 file as the local codepage unless it begins with a byte order mark, which shows up as mojibake in accented characters.
Frequently asked questions
Why are numbers quoted as strings in the JSON output?
Because CSV carries no type information. Automatic conversion would
corrupt values like 007 or 1.10. Cast the fields you
need after conversion.
Can it handle fields containing commas?
Yes, provided they are quoted per the CSV convention. Quoted fields may also contain newlines and escaped double quotes.
What happens if my JSON objects have different fields?
The header row becomes the union of all keys in first-appearance order, and records missing a field get an empty cell. No error is raised.
Can I convert nested JSON to CSV?
Not directly, since CSV has no representation for nesting. Flatten the structure into dotted column names first.
Does it support semicolon-separated files?
This converter uses commas, which is the RFC 4180 convention. For semicolon-separated exports from a German Excel installation, replace the separators first or re-export with commas.
Is my data sent to a server?
No. Parsing and conversion happen entirely in your browser, so converting files containing customer or production data is safe.
Related tools
- JSON formatter, to tidy the converted output
- JSON to C# classes, to generate typed models
- Text diff viewer, to compare two exports
- All developer tools