How to use JSON to SQL INSERT
- Paste your data into JSON array of objects. A single object also works and becomes one row.
- Type the Table name. You can include a schema, such as
dbo.people. - Pick the SQL dialect: PostgreSQL, MySQL / MariaDB, SQLite or SQL Server.
- Tick One multi-row INSERT to group rows into one statement, and Include CREATE TABLE if the table does not exist yet.
- Copy the SQL or download it as a
.sqlfile. The stats show how many rows and columns were written.
What it does and when to use it
Use it to seed a test database from an API response or turn fixture files into a migration. Each object becomes one row and each key a column. The dialect changes only what differs between databases: name quoting, booleans and CREATE TABLE types.
If the JSON will not parse, check it first with the JSON validator or fix it with JSON repair. To tidy the generated SQL, paste it into the SQL formatter.
How it works
The tool parses your JSON in the browser and collects the union of all keys as columns. Values are then written by type:
| JSON value | PostgreSQL / MySQL / SQLite | SQL Server |
|---|---|---|
| string | 'text', with ' doubled to '' |
same, prefixed with N if it has non-ASCII characters |
| number | as written | as written |
true / false |
TRUE / FALSE |
1 / 0 |
null or missing |
NULL |
NULL |
| object or array | JSON text in quotes | JSON text in quotes |
Identifiers are quoted with double quotes on PostgreSQL and SQLite, backticks on MySQL and square brackets on SQL Server. With One multi-row INSERT, rows are grouped 500 per statement, which keeps SQL Server under its limit of 1,000 rows in one VALUES list.
CREATE TABLE types come from each column’s values: whole numbers become BIGINT (INTEGER on SQLite), decimals a floating type, booleans BOOLEAN (BIT on SQL Server), and the rest text. No keys or constraints are added.
Worked examples
PostgreSQL with a quote and an array. Two users, one called O’Neil with a tags array, one without tags:
INSERT INTO "users" ("id", "name", "active", "tags") VALUES (1, 'O''Neil', TRUE, '["a","b"]');
INSERT INTO "users" ("id", "name", "active", "tags") VALUES (2, 'Zoë', FALSE, NULL);
SQL Server with CREATE TABLE. Table dbo.people, one row named Zoë. The columns get BIGINT, NVARCHAR(MAX), BIT and FLOAT, and the insert ends VALUES (1, N'Zoë', 0, 9.5);. The N prefix keeps the ë intact.
SQLite, multi-row. Two items with different keys give the columns sku, qty, price:
INSERT INTO "items" ("sku", "qty", "price") VALUES
('A1', 3, NULL),
('B2', NULL, 4.25);
Limits and tips
- Top-level shape. The input must be an object or an array of objects.
[1, 2]returns an error, because a plain value has no column names. - No dates or special types. A date string is inserted as text; cast it in SQL if needed.
- Review before you run. Treat CREATE TABLE as a starting point and add keys yourself.
Frequently asked questions
What happens when objects have different keys?
How are nested objects and arrays stored?
Can I give a schema name such as dbo.people?
Are very large ID numbers safe?
Is the output safe to run against a production database?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.