JSON to SQL INSERT statements for PostgreSQL, MySQL, SQLite and SQL Server

Paste a JSON array of objects and get one SQL INSERT per object, with identifiers and strings quoted the way PostgreSQL, MySQL, SQLite or SQL Server expect.

Live demo · real result from this tool

SQL

INSERT INTO "users" ("id", "name", "city", "score", "active") VALUES (1, 'Asha', 'Pune', 92.5, TRUE);INSERT INTO "users" ("id", "name", "city", "score", "active") VALUES (2, 'Ben', 'Leeds', 78, FALSE);INSERT INTO "users" ("id", "name", "city", "score", "active") VALUES (3, 'Chen', 'Taipei', 85.25, TRUE); 
Rows3
Columns
5

Processed on your device — nothing is uploaded.

How to use JSON to SQL INSERT

  1. Paste your data into JSON array of objects. A single object also works and becomes one row.
  2. Type the Table name. You can include a schema, such as dbo.people.
  3. Pick the SQL dialect: PostgreSQL, MySQL / MariaDB, SQLite or SQL Server.
  4. Tick One multi-row INSERT to group rows into one statement, and Include CREATE TABLE if the table does not exist yet.
  5. Copy the SQL or download it as a .sql file. 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?
The tool collects every key it sees, in the order it first appears, and uses that full list as the column list for every row. A row that lacks a key gets NULL in that column.
How are nested objects and arrays stored?
They are written as a JSON string, so ["a","b"] becomes the text '["a","b"]'. With "Include CREATE TABLE" ticked, such columns get JSONB on PostgreSQL, JSON on MySQL, NVARCHAR(MAX) on SQL Server and TEXT on SQLite.
Can I give a schema name such as dbo.people?
Yes. The table name is split at each dot and every part is quoted on its own, so dbo.people becomes [dbo].[people] on SQL Server or "dbo"."people" on PostgreSQL.
Are very large ID numbers safe?
Yes, in current browsers. Integers above 9,007,199,254,740,991 are written with the digits you typed, so 9007199254740993 stays 9007199254740993. A browser that cannot read the original digits rounds them and shows a warning; store such IDs as strings if you need to be sure.
Is the output safe to run against a production database?
Quoting is correct for plain values, but review the SQL and run it in a transaction first. In application code, use parameterised queries rather than building SQL text.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close