JSON to SQL

Turn a JSON array into a CREATE TABLE with inferred column types and batched INSERT statements — for PostgreSQL, MySQL, SQLite or SQL Server.

JSON to SQL runs entirely in your browser. Your data is converted on your device and never uploaded.

Open the CSV to SQL converter

About JSON to SQL

JSON to SQL takes an array of objects — an API response, an export, a fixture file — and produces the two statements that get it into a database: a CREATE TABLE whose column types are inferred from every value in each column, and INSERT statements batched into multi-row VALUES lists. Type inference is done properly: integers that exceed 32 bits become BIGINT, ISO-formatted strings become TIMESTAMP, mixed columns degrade safely to TEXT, and each canonical type is rendered in the target dialect's spelling — BOOLEAN arrives as TINYINT(1) in MySQL and BIT in SQL Server. The details that break hand-written scripts are exactly the point: identifiers are quoted per dialect so a column named order never collides with the keyword, single quotes in values double correctly so O'Brien survives, missing keys become NULL, and nested objects serialise as JSON text.

Features

How to use the JSON to SQL

  1. Paste a JSON array of objects (or one object)
  2. Name the table and pick the dialect
  3. Adjust the rows-per-INSERT batch size if needed
  4. Copy the SQL — types are listed for review first

Example

Input

[{"id":1,"name":"O'Brien","active":true}]

Output

CREATE TABLE "users" ("id" INTEGER, "name" TEXT, "active" BOOLEAN);
INSERT INTO "users" ("id", "name", "active") VALUES (1, 'O''Brien', TRUE);

The doubled quote in O''Brien is what keeps the script valid.

Common errors & troubleshooting

Frequently asked questions

How are column types inferred from JSON?
Every value in a column votes: whole numbers give INTEGER (or BIGINT past 32 bits), any decimal makes it DOUBLE PRECISION, true/false give BOOLEAN, ISO-dated strings give TIMESTAMP, and any conflict — or any real string — settles on TEXT. All rows are scanned, so a late float cannot corrupt an integer column.
What changes between the SQL dialects?
Identifier quoting (double quotes, `backticks`, [brackets]), type spellings (BOOLEAN vs TINYINT(1) vs BIT, DOUBLE PRECISION vs DOUBLE vs FLOAT vs REAL), boolean literals (TRUE vs 1), and the N'' prefix SQL Server wants on Unicode text.
How are objects with different keys handled?
Columns are the union of keys across all rows, in first-seen order; rows missing a key insert NULL there. That matches how heterogeneous API data usually needs to land in a table.
What happens to nested objects and arrays?
They serialise to their JSON text and store in a TEXT column — queryable later with the database's own JSON functions, castable to jsonb in PostgreSQL. Flatten the structure first if you want them as real columns.
Is the generated script production-ready?
It is import-ready: syntactically safe quoting and sane types. Production tables still deserve a primary key, NOT NULL constraints and indexes, which no inference can guess from data alone — review the type list, then harden.

Related tools

All ArrayKit tools