Table to JSON converter

Convert CSV, Excel / Google Sheets cells or MySQL and PostgreSQL result tables to JSON, a PHP array or a JavaScript object.

Your text is processed in your browser and never sent to our server.

0 characters · 0 words · 0 lines

How to convert CSV, Excel or SQL results to JSON

This converter turns any table pasted as text into JSON, a PHP array or a JavaScript object. It understands CSV files, cells copied from Excel or Google Sheets and the result tables printed by the MySQL and PostgreSQL command line clients.

  1. Paste the table into the input box, open a .csv file or drop it onto the box.
  2. The format is detected automatically – check the Format badge under the result and pick it manually if the guess is wrong.
  3. Choose the output: JSON objects, JSON arrays, a PHP array or a JavaScript object.
  4. Copy the result or download it as a file.

What the options do

  • Input format – CSV with commas or semicolons (quoted values with commas, quotes and line breaks are supported), tab separated text (Excel, Google Sheets, mysql -e), or an SQL client table with +----+ borders, psql output and Markdown tables. MySQL vertical output (\G) works too.
  • First row is the header – the first row becomes the keys. When turned off, keys are col1, col2, …
  • Output – array of objects is what most APIs expect, array of arrays keeps only the values, PHP array uses the short [ ] syntax ready for a Laravel seeder.
  • Convert numbers, booleans and null – 42 becomes a number, true/false booleans and NULL null. Values with leading zeros such as ZIP codes stay text.
  • Indent – pretty print with 2 or 4 spaces, or minify to a single line.

Examples

CSV to JSON

id,name,city,active
1,Ján Novák,Bratislava,true
2,"Smith, Anna","New York",false
3,Peter,,true

becomes an array of objects (note the quoted value with a comma and the converted booleans):

[
  {
    "id": 1,
    "name": "Ján Novák",
    "city": "Bratislava",
    "active": true
  },
  {
    "id": 2,
    "name": "Smith, Anna",
    "city": "New York",
    "active": false
  },
  {
    "id": 3,
    "name": "Peter",
    "city": "",
    "active": true
  }
]

SQL result to a PHP array for seeders

Copy the output of a query from the mysql client:

+----+-------------+---------------------+
| id | name        | email               |
+----+-------------+---------------------+
|  1 | Ján Novák   | jan@example.com     |
|  2 | Anna Smith  | NULL                |
+----+-------------+---------------------+
2 rows in set (0.00 sec)

Choose PHP array and paste the result straight into DB::table('users')->insert(…) in your seeder:

[
    [
        'id' => 1,
        'name' => 'Ján Novák',
        'email' => 'jan@example.com',
    ],
    [
        'id' => 2,
        'name' => 'Anna Smith',
        'email' => null,
    ],
];

Frequently asked questions

How do I convert Excel to JSON?

Select the cells in Excel or Google Sheets including the header row, press Ctrl+C (Cmd+C on Mac) and paste them here. Copied cells are tab separated, which the tool detects as TSV. Cells with line breaks are handled too.

How do I turn an SQL query result into JSON?

Run the query in the mysql or psql client and copy the printed table including the header. Prompt lines and footers like 2 rows in set are ignored. With mysql -e "SELECT …" the output is tab separated, which works as well.

My CSV uses semicolons – is that supported?

Yes. Excel in many European locales (including Slovak) saves CSV with semicolons. The tool detects it, or you can pick CSV (semicolon) manually.

Is my data uploaded anywhere?

No. The conversion runs locally in your browser, so you can safely paste customer lists or database exports.

Why are some numbers kept as strings?

Values like 007, 1,5 or IDs longer than 15 digits would lose information as JSON numbers, so they stay text. Turn off the conversion to keep every value as a string. To compare two exports, use the text compare tool.