Resell services with the EthicalSMM API

JSON to SQL INSERT

Turn a JSON array of objects into SQL INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server, with safe quoting and NULLs.

Was this tool helpful?

Thanks for the feedback!

This tool turns a JSON array of objects into SQL INSERT statements for MySQL or MariaDB, PostgreSQL, SQLite or SQL Server. It quotes table and column names the way each database expects, escapes text safely and writes NULL where a value is missing. It is handy for developers seeding a test database or loading an API export, and the conversion runs in your browser.

The fields

Paste your JSON into the main box. It should be an array of objects such as [{"id": 1, "name": "Asha"}]; a single object is accepted and treated as one row. Table name defaults to my_table, and a name with a dot such as sales.customers is quoted as schema and table. Database picks the dialect. Statements chooses between "One multi-row INSERT" and "One INSERT per row".

How values are written

The column list is every key found in any row, in the order they first appear. Each value is then written like this:

JSON valueMySQLPostgreSQLSQLiteSQL Server
Column name`name`"name""name"[name]
true / falseTRUE / FALSETRUE / FALSE1 / 01 / 0
Missing key or nullNULLNULLNULLNULL

A nested object or array is stored as JSON text in single quotes, for example '{"tier":"gold"}', which suits a JSON or text column. Numbers are written as they are. Text goes in single quotes, and any apostrophe inside is doubled, so O'Brien becomes 'O''Brien'. A quote character inside a column name is doubled in the same way, so a backtick in a MySQL column name becomes two backticks. For SQL Server, text that contains any non-ASCII character, such as Hindi script or the ₹ sign, gets an N prefix (N'रवि') so it is stored as Unicode in an NVARCHAR column.

In multi-row mode, the tool starts a new INSERT every 500 rows, or every 1,000 rows for SQL Server, which does not allow more than 1,000 rows in one VALUES list. So 1,200 rows become three statements for MySQL and two for SQL Server. Smaller batches also keep each statement a manageable size for any database.

Worked example

Input, with table customers and PostgreSQL:

[{"id":1,"name":"Asha","city":"Pune","active":true},
 {"id":2,"name":"O'Brien","active":false,"meta":{"tier":"gold"}}]

Output:

INSERT INTO "customers" ("id", "name", "city", "active", "meta") VALUES
  (1, 'Asha', 'Pune', TRUE, NULL),
  (2, 'O''Brien', NULL, FALSE, '{"tier":"gold"}');

Row 2 has no city and row 1 has no meta, so both get NULL. The stats show 2 rows and 5 columns. Choosing SQLite instead changes TRUE and FALSE to 1 and 0 and keeps the double quotes. For SQL Server with table sales.customers, the header becomes INSERT INTO [sales].[customers] ([id], [name], [active]) VALUES.

Limits and good practice

  • Input that is not an array of objects, such as [1,2,3] or an empty array, gives "Paste an array of objects, for example [{"id":1,"name":"Asha"}]."
  • Columns appear in the order keys are first seen. If the first row lacks a key that a later row has, that column is added at the end of the list, and earlier rows get NULL for it.
  • The tool writes only INSERT statements. Create the table first, with column types that match your data.
  • Dates stay as text such as '2026-12-04'. Most databases convert ISO dates into a DATE column on insert, but check yours.
  • A number too large for JSON to hold, such as 1e400, is written as NULL.
  • Use the output for scripts, seed files and one-off loads. Application code should use parameterised queries rather than building SQL strings.

Have a CSV file instead? Use the CSV to SQL converter. To lay out a long statement neatly, paste it into the SQL formatter.

Frequently asked questions

How do I convert JSON to SQL INSERT statements?
Paste a JSON array of objects, type the table name, choose your database and press Generate SQL. Each object becomes one row and each key becomes a column.
How are apostrophes in text escaped in the SQL?
Each single quote inside a value is doubled, which is the standard SQL way to escape it. The name O'Brien is written as 'O''Brien'.
What happens when some JSON objects are missing a key?
The tool collects every key from every row as a column. Any row that lacks a key gets NULL in that column, as does any value that is null in the JSON.
Why do some strings start with N in the SQL Server output?
SQL Server needs the N prefix to treat a string literal as Unicode. The tool adds it to any text with non-ASCII characters, such as Hindi script or the ₹ sign, so it is not mangled.
How many rows does the tool put in one INSERT statement?
In multi-row mode it starts a new INSERT every 500 rows, or every 1,000 rows for SQL Server, which allows at most 1,000 rows in one VALUES list. Choose One INSERT per row if you want a separate statement for every row.
Does the tool create the table as well?
No. It writes INSERT statements only, so create the table with suitable column types before running them.

Related guides

Related tools

People also used

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.