CSV and JSON Converter
Convert CSV text to a JSON array, or a JSON array to CSV. Handles quoted fields, line breaks, and comma, semicolon or tab delimiters.
CSV to JSON: the first row gives the keys of each object. JSON to CSV: when this is ticked, objects get a headings row. An array of arrays never gets one.
How to use
- Under Direction, choose CSV to JSON or JSON to CSV. The two text boxes relabel themselves to match.
- Under Delimiter, pick comma, semicolon or tab. This is the character that separates fields in the CSV, whichever direction you are converting. Spreadsheets in many European locales save CSV with semicolons.
- Tick or clear First row is the headings. Ticked, the first CSV row names the keys. Cleared, each CSV row becomes a plain array.
- Paste your data into the input box. The tool converts as you type, and the Convert button runs it again.
- Read the output box and the status line below it. Press Copy to copy the output. Errors name the problem and the place it was found.
Worked example
The page opens with this CSV, which has a comma inside one value and quotation marks inside another:
name,note,qty Apple,"red, sweet",3 Pear,"says ""hi""",0
With CSV to JSON, comma and headings ticked, the output is:
[
{
"name": "Apple",
"note": "red, sweet",
"qty": "3"
},
{
"name": "Pear",
"note": "says \"hi\"",
"qty": "0"
}
]
Notice that qty is the string "3", not the number 3. The tool never guesses types.
Now the other direction. Switch to JSON to CSV and paste [{"id":1,"city":"Oslo, NO","delta":-2},{"id":2,"city":"Rome","note":"=SUM(A1)"}]. The headings are every key seen, in first-seen order, and the output is:
id,city,delta,note 1,"Oslo, NO",'-2, 2,Rome,,'=SUM(A1)
The second row has no delta, so that cell is empty. The value -2 and the text =SUM(A1) each get a leading apostrophe, for the reason explained below. Lines in the output end with CRLF (a carriage return and a line feed), the line ending RFC 4180 specifies.
How it works
CSV to JSON reads CSV in the style of RFC 4180. A field in double quotes can hold the delimiter and line breaks, and two double quotes inside it stand for one. Both LF and CRLF line endings work, and empty lines are skipped. With the headings box ticked, the first row gives the keys and each later row becomes one object. Without it, each row becomes an array.
JSON to CSV takes a JSON array of objects or of arrays, as defined by RFC 8259. A missing key or a null value gives an empty cell. Numbers and booleans are written as text.
Quoting rule. A field is quoted only when it contains the delimiter, a double quote or a line break. Each double quote inside a quoted field is doubled.
Formula safety. A value that starts with =, +, -, @, a tab or a carriage return gets a single apostrophe in front. Spreadsheet programs can run such a cell as a formula, which is a known attack called CSV injection. See the OWASP page on CSV injection. The side effect is that a genuine negative number, such as -2, is written as '-2.
Common mistakes and edge cases
- Wrong delimiter. If every row collapses into one field, the file probably uses semicolons or tabs. Change the delimiter setting.
- Rows with different lengths. A row with too few or too many fields is refused, for example
Data row 2 has 1 field, but the headings have 2.Fix the row rather than guess which column is missing. - Duplicate headings. Two columns with the same name would overwrite each other as JSON keys, so the tool refuses them.
- Nested JSON. An object or array inside a value cannot fit in one cell. Flatten it first.
- Leading zeros. Because values stay as text,
007survives. Opening the CSV in a spreadsheet may still strip the zeros, which is the spreadsheet's doing.
Frequently asked questions
Why are my numbers in quotes?
CSV has no types. Every field is text, so the tool keeps text and leaves type conversion to the code that reads the JSON, where the right type is known.
Is RFC 4180 a strict standard?
It is an informational document that records common practice, and real files vary. This tool follows it for quoting and line endings and refuses input it cannot read without guessing.
What happens to non-English text?
It is kept as typed. The tool works with the characters your browser gives it, so accents and other scripts pass through unchanged.
Can I convert a very large file?
The conversion happens on one page in memory, so very large inputs can make the tab slow. Split big files first.
Does my data leave the browser?
No. Nothing you paste is uploaded or stored.
Related tools
- JSON Formatter & Validator to tidy the JSON you get out, or check JSON before converting it.
- Diff Checker to compare two versions of a CSV export.
- Base64 & URL Encoder/Decoder for data that has to travel inside a URL or a header.
- Regex Tester to clean up messy values before converting.