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 value | MySQL | PostgreSQL | SQLite | SQL Server |
|---|---|---|---|---|
| Column name | `name` | "name" | "name" | [name] |
| true / false | TRUE / FALSE | TRUE / FALSE | 1 / 0 | 1 / 0 |
| Missing key or null | NULL | NULL | NULL | NULL |
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
NULLfor it. - The tool writes only
INSERTstatements. 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 asNULL. - 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?
How are apostrophes in text escaped in the SQL?
What happens when some JSON objects are missing a key?
Why do some strings start with N in the SQL Server output?
How many rows does the tool put in one INSERT statement?
Does the tool create the table as well?
Related guides
- Free Developer Tools That Replace a Dozen Browser Tabs Free developer tools grouped by job: format, convert, encode, generate and test. What each one does, which run on the server, and the limits to know f...
- How to Beautify CSS, HTML and XML (Online, VS Code, Prettier) Beautifying adds line breaks and indentation so minified CSS, HTML or XML is readable again. How the free formatters work, their limits, and VS Code a...
- How to Format JSON: Pretty-Print, Validate and Read Errors Paste JSON into a formatter to indent it and catch errors. The exact syntax rules, how to read an error position, and how to do it in VS Code, Python...