Skip to content
Tools

JSON to SQL INSERT Generator

Last updated:

Paste a JSON array of objects and get SQL INSERT statements, one column per key across all rows. String values are quoted with single quotes, embedded quotes are doubled, and JSON null (or a missing key) becomes SQL NULL. The tool writes INSERTs only, not CREATE TABLE, so the table must already exist.

Runs in your browser: your data never leaves your device – nothing is uploaded, logged or stored on a server. How we protect your data

100% in-browserNothing is uploaded

Input

Loading editor…

Paste JSON here

or drop a file anywhere in this box. Everything stays in your browser.

Drop a file to load it

Output

Loading editor…

SQL appears here

Results update as you type.

How to use the JSON to SQL

  1. Paste a JSON array of objects (a single object becomes one row).
  2. Set the table name; schema.table is quoted part by part.
  3. Pick the identifier quoting: double quotes (PostgreSQL, SQLite), backticks (MySQL), brackets (SQL Server) or none, and whether to emit one multi-row INSERT or one statement per row.
  4. Run the script in a development database first, then copy it wherever it is needed.

Worked example

Two rows, one with an apostrophe and a null

Input

[{"id":1,"name":"O'Brien","active":true,"score":null},{"id":2,"name":"Ada","active":false,"score":9.5}]

SQL

INSERT INTO "my_table" ("id", "name", "active", "score") VALUES
  (1, 'O''Brien', TRUE, NULL),
  (2, 'Ada', FALSE, 9.5);

Default settings: table my_table, double-quoted identifiers, one multi-row INSERT. The apostrophe in O'Brien is escaped by doubling it; numbers keep their exact digits.

How JSON values are written

How JSON values are written
JSON valueSQL literalDatabase note
NumberAs written, e.g. 9.5Digits are copied exactly, so big IDs keep precision
true / falseTRUE / FALSEMySQL stores as TINYINT(1); SQLite as 1/0; SQL Server has no TRUE keyword, use 1/0
String'text' with ' doubledStandard escaping; with backtick (MySQL) quoting, backslashes are also doubled (\\) so MySQL reads them literally
null or missing keyNULLUnquoted keyword
Nested object or arrayCompact JSON as a string, e.g. '{"a":1}'Insert into a JSON/JSONB or TEXT column

Quoting: values vs. identifiers

In standard SQL, single quotes delimit string values ('Ada') and double quotes delimit identifiers ("order"). MySQL uses backticks and SQL Server brackets, which is why the quoting option exists. Column names that are reserved words, such as order, user or group, or that contain spaces, must be quoted as identifiers or the statement fails.

Escaping is done by doubling the quote character, which every major database supports. MySQL also treats a backslash inside a string as an escape character by default, so when you pick backtick (MySQL) quoting the tool doubles every backslash too, and C:\temp is stored exactly as written.

Generated SQL is for seeding, not for user input

A generated script is fine for test fixtures, demos and one-off imports. Application code should never build SQL by concatenating strings; use parameterized queries so the driver handles quoting. For big imports, COPY (PostgreSQL) or LOAD DATA (MySQL) from CSV is far faster than thousands of INSERTs.

JSON to SQL FAQ

How do I escape a single quote in SQL?

Double it: 'O''Brien' stores O'Brien. This is standard SQL and works in PostgreSQL, MySQL, SQL Server, SQLite and Oracle.

Does the tool generate CREATE TABLE?

No, only INSERT statements. Create the table first with column types that suit your data, e.g. BIGINT for IDs, NUMERIC for money and JSONB (PostgreSQL) or JSON (MySQL) for nested values.

How is JSON null converted to SQL?

As the keyword NULL, unquoted. A quoted 'null' would insert the four-letter string instead.

What happens to nested objects when converting JSON to SQL?

Relational columns hold single values, so nested objects and arrays are stored as JSON text. Put them in a JSON/JSONB column or split them into a child table.

Can I import JSON directly into PostgreSQL without INSERTs?

Yes. Load the file as one jsonb value and use jsonb_to_recordset or jsonb_array_elements in an INSERT … SELECT to expand it into rows.

Why does my INSERT fail with a syntax error near a column name?

The column is probably a reserved word like order or user. Quote it as an identifier: "order" in PostgreSQL and SQLite, `order` in MySQL.

Related tools