Skip to content

CSV To JSON Converter

Turn a header row and data rows into a JSON array. a,b followed by 1,2 becomes one object with a set to 1 and b set to 2. The page does not open a file.

Result

Paste CSV

How to Use

  1. 1 Paste a header and at least one data row.
  2. 2 Choose Convert to JSON.
  3. 3 a,b and 1,2 is one JSON object.

Example Output

  • a,b 1,2

About This Tool

The first non-blank row is the header. Later rows must have the same number of columns. Values stay text.

Using the CSV to JSON Converter

The CSV to JSON Converter turns a header row and one or more data rows into a JSON array. The field starts as a,b on the first line and 1,2 on the second line. Choose Convert to JSON. The label above the headline reads JSON. The headline is 1 row. The rows line is 1. The columns line is 2. The JSON text is an array with one object. In that object, a is set to the text 1 and b is set to the text 2. The sample text includes "a": "1" and "b": "2". The first row is the header. Values stay text. The page does not open a file.

The page skips blank lines, trims each header, and trims each value. a,b and 1,2 become the keys a and b and the text values 1 and 2. A second data line 3,4 adds a second object, and the headline becomes 2 rows. Every data row must have the same number of columns as the header. A row with a different count is rejected with Each row needs the same number of columns. A blank header, or a repeated header, is rejected with Give every column a header, and do not repeat a header. The JSON is indented so the keys and the text values are easy to read.

The paste must be from 1 to 20000 characters. A field that is empty after trimming, or a paste longer than 20000 characters, is rejected with Enter from 1 to 20000 characters. A header with no data row is rejected with Enter a header row and at least one data row. The rejection replaces the headline and clears the JSON text and the lines. The same CSV always produces the same JSON. Convert the sample twice and the headline stays 1 row, with a set to the text 1 and b set to the text 2.

Copy result copies the JSON text. Reset returns the field to a,b and 1,2 and the headline to Paste CSV. The JSON text and the lines are cleared. Copy before you reset if you still need the array. Convert to JSON again after a reset when you want the headline 1 row back. The waiting line Paste CSV is not JSON. The page reads the paste in the field. It does not open a file.

What the JSON Object Contains

The JSON is an array of objects, one object for each data row. For a,b and 1,2 the array has one object, so the headline is 1 row. Inside that object, a is the text 1 and b is the text 2. The values stay text. They are not JSON numbers, even though they look like digits. The rows line is 1 and the columns line is 2. The label above the headline reads JSON. The steps say to read the first row as headers, build one object per later row, and encode the objects as JSON.

The first non-blank row is the header. Later non-blank rows are the data. Blank lines between them are skipped, so a blank line under a,b does not create an empty object and does not change the headline from 1 row when 1,2 is the only data row. The page does not open a file. The field is the whole input. Quote a value when it contains a comma, and the comma stays inside that one text value.

How a,b and 1,2 Become One Object

The page checks the length, drops blank lines, and reads the first remaining row as the header. a and b are the keys after trimming. The next row supplies the values. 1 and 2 are trimmed and stored as text. The object sets a to the text 1 and b to the text 2. The headline counts data rows, which is 1 row. The columns line counts header cells, which is 2. A third column in the header would require a third cell in every data row, and the columns line would be 3.

The reverse direction starts from JSON. The JSON to CSV Converter turns a JSON array of objects into CSV. [{"a":1,"b":2}] becomes a header row a,b and a data row 1,2. Download CSV saves the rows. Objects may omit a key, and the missing cell stays empty. Use it when you already have the JSON array. Use this page when you have the CSV and want the JSON, with values kept as text. The sample headline is 1 row.

What the Converter Does Not Fetch

The page does not open a file. It does not browse a disk, and it does not fetch a sheet from a network. Paste the CSV into the field. A header and at least one data row are required. a,b alone is rejected with Enter a header row and at least one data row. The page also does not invent a header from the first data row. If the first row is 1,2 and the second is 3,4, the keys are the text 1 and the text 2, and the object values are the text 3 and the text 4. Put a,b on the first row when those should be the keys.

Values stay text on the way into JSON. A value 1 is the text 1, not a JSON number. A value true is the text true, not a JSON boolean. If you need numbers in the JSON, that is an edit after you copy the text this page builds. The indented array from the sample already shows a and b as text.

One Row From a,b and 1,2

Leave the field as a,b and 1,2. Choose Convert to JSON. The headline is 1 row. The rows line is 1. The columns line is 2. The object sets a to the text 1 and b to the text 2. Convert again. The headline stays 1 row. Add a line 3,4 and convert. The headline is 2 rows, the columns line stays 2, and the second object sets a to the text 3 and b to the text 4. Remove 3,4 and confirm the headline is 1 row again. Put a blank line between the header and 1,2. The headline is still 1 row, because the blank line is skipped.

A column check that counts every line is a different reading of the same paste. The CSV Validator checks that pasted CSV rows have the same number of columns. a,b and 1,2 is Valid, with 2 rows and 2 columns. That page does not open a file. Use it when you want the Valid check and a row count that includes the header. Use this page when the headline should count data rows, so the same paste is 1 row and the values stay text.

Headers, Width, and the 20000 Character Cap

The paste must be from 1 to 20000 characters. Enter from 1 to 20000 characters covers a blank field and a longer paste. The page does not keep the first part of an oversized paste. Enter a header row and at least one data row covers a single line. Give every column a header, and do not repeat a header covers an empty header cell and a repeated name such as a,a. Each row needs the same number of columns covers a data row that is shorter or longer than the header. The headline and the JSON are cleared when any of these checks fail.

A successful header is a set of trimmed names, each different and each non-empty. A successful data row has one trimmed text value for each name. The sample header is a and b. The sample values are the text 1 and the text 2. Quoted commas stay inside one cell, so a quoted value can contain a comma without becoming an extra column. The page does not open a file to find more rows. What you paste is what is converted.

CSV Shapes People Expect JSON to Repair

A common miss is to expect the values 1 and 2 to become JSON numbers. Values stay text. The object sets a to the text 1 and b to the text 2. Another miss is to count the header in the headline. The headline is 1 row for one data row. The columns line is 2. Another miss is to omit the header and expect a and b to appear anyway. The first row is the header. Another miss is to repeat a header name. a,a is rejected. Another miss is to leave a data row short. a,b followed by 1 is rejected with Each row needs the same number of columns.

JSON you already have is formatted on another page. The JSON Prettifier formats JSON with line breaks and four-space indentation. {"a":1} becomes a readable object that still contains a and 1. That page does not fetch JSON. Use it when the paste is already JSON. Use this page when the paste is CSV. a,b and 1,2 become 1 row, with text values.

One Row, Two Rows, and a Broken Width

Convert the sample. Confirm the headline is 1 row, the columns line is 2, and the object sets a to the text 1 and b to the text 2. Add 3,4 and convert. Confirm the headline is 2 rows and the second object uses the text 3 and the text 4. Change the second line to 1 and convert. The headline reads Each row needs the same number of columns. Restore 1,2. Change the header to a,a and convert. The headline reads Give every column a header, and do not repeat a header. Restore a,b and convert. The headline is 1 row.

Clear the field and convert. The headline reads Enter from 1 to 20000 characters. Type only a,b and convert. The headline reads Enter a header row and at least one data row. Restore a,b and 1,2 and convert once more. Copy the JSON if that one object is the record you want. The page does not open a file. Values in the copy stay text.

Saving the JSON With the Row Count

Copy result copies the JSON text. For the sample, the copy is the indented array whose one object sets a to the text 1 and b to the text 2. Write the headline beside it if your note needs the count: 1 row, 2 columns. Reset returns the field to the sample CSV and clears the JSON, so the copy is the record. Convert again if you need the page to show 1 row once more. A later edit of the CSV needs a new copy, because the page does not keep the previous JSON after the next run.

A compact line is a different spacing of JSON you already have. The JSON Minifier removes insignificant space from a JSON value. {"a": 1} becomes {"a":1}. That page parses the text first, so a broken value is rejected instead of being trimmed by hand. Use it when you want the compact form of JSON. Use this page when you are starting from CSV and the values should stay text. The sample headline is 1 row.

A Header, Data Rows, and Text Values

Every successful conversion reads the first non-blank row as the header and builds one object per later row. a,b then 1,2 is 1 row. The object sets a to the text 1 and b to the text 2. Values stay text. The columns line is 2. The page does not open a file. A second data row makes the headline 2 rows. A mismatched width, a repeated header, a missing data row, and an empty paste are rejected, and the JSON is cleared.

Checks Before You Copy the JSON

Confirm the first row is the header you want as keys. Confirm every data row has that many cells. Confirm the headline counts data rows, not the header. For a,b and 1,2, the headline is 1 row, the columns line is 2, and the values are the text 1 and the text 2. An error headline means no JSON was produced. The message names a length problem, a missing data row, a bad header, or a width mismatch. Fix the paste and convert once.

Indented markup in another format is a different paste. The XML Formatter indents an XML document. <a><b>Hi</b></a> is formatted with each element on its own line. That page does not fetch a file and does not accept a document type. Use it when the paste is XML. Use this page when the paste is CSV with a header and data rows. The sample stays 1 row, with a set to the text 1 and b set to the text 2.

Frequently Asked Questions

What do a,b and 1,2 return?

The headline is 1 row. The rows line is 1 and the columns line is 2. The JSON array has one object. That object sets a to the text 1 and b to the text 2. The first row is the header. Values stay text. The page does not open a file.

Do the values stay text?

Yes. Values stay text. 1 and 2 are the text 1 and the text 2, not JSON numbers. A value that looks like true stays the text true. The indented JSON shows those text values under the keys from the header row.

Which row is the header?

The first non-blank row is the header. Later non-blank rows are data. Blank lines are skipped. a,b is the header in the sample, and 1,2 is the one data row, so the headline is 1 row. A header without a data row is rejected.

What if a data row is short?

Each row needs the same number of columns. a,b followed by 1 is rejected, and the JSON is cleared. Add the missing cell or remove the extra header and convert again. Quoted commas stay inside one cell, so a comma inside quotes does not add a column.

What if a header is repeated?

Give every column a header, and do not repeat a header. a,a is rejected. An empty header cell is rejected with the same message. The sample headers a and b are different and non-empty, so they become the keys a and b.

Does the page open a file?

No. The page does not open a file. Paste the CSV into the field. The cap is 20000 characters. A blank field and a longer paste are rejected with Enter from 1 to 20000 characters. The page does not keep a prefix of an oversized paste.

What does a second data row change?

The headline becomes 2 rows. a,b followed by 1,2 and 3,4 produces two objects. The first sets a to the text 1 and b to the text 2. The second sets a to the text 3 and b to the text 4. The columns line stays 2.

What does reset restore?

The field returns to a,b and 1,2. The headline returns to Paste CSV. The JSON text and the lines are cleared. Choose Convert to JSON again when you want the headline 1 row and the object that sets a to the text 1 and b to the text 2.