JSON to SQL INSERT Generator

Turn a JSON object or an array of objects into ready-to-run SQL INSERT statements. Pick a dialect — MySQL, PostgreSQL, SQLite or SQL Server — and it quotes identifiers and string literals correctly for that database, emits NULL for nulls, renders booleans the right way, and serializes nested objects as JSON. Choose whether to include a column list and whether to produce one multi-row statement (batched to a size you set) or one row per statement. It runs entirely in your browser.

How to use the JSON to SQL INSERT Generator

Paste a JSON object or an array of objects, set the table name, and pick the dialect for your target database. The column list is the union of all keys across the rows, in first-seen order, so heterogeneous records still line up — any row missing a key gets NULL in that position. Toggle include column names to emit the explicit (col1, col2, …) list (recommended; without it the column order must match your table exactly), and multi-row INSERT to combine rows into batched VALUES (…),(…) statements rather than one statement each.

The dialect choice controls quoting, which is the part that's tedious and easy to get wrong by hand. Identifiers are wrapped per database — backticks for MySQL, double quotes for PostgreSQL and SQLite, square brackets for SQL Server — and only when the name needs it. String literals are escaped by doubling the single quote (and additionally escaping backslashes for MySQL, whose default mode treats \\ specially). Booleans become TRUE/FALSE for PostgreSQL and 1/0 elsewhere; null becomes NULL; and nested objects or arrays are serialized to a JSON string so they fit a JSON/JSONB or text column. Set rows per statement to keep batched inserts under your database's packet or parameter limits. Always review the generated SQL before running it against a real database.

Generating INSERT statements safely from JSON

Loading JSON into a relational table is a routine chore — seeding a database, importing an API response, migrating a document store into SQL — and the mechanical part is turning each object into a row of an INSERT statement. Doing it by hand is slow and risky, because the details that matter are exactly the ones easy to fumble: how identifiers and string literals are quoted, how a stray apostrophe is escaped, how nulls and booleans are written, and how the columns of uneven records line up.

Those details are dialect-specific, which is why a generic "JSON to SQL" string substitution breaks in practice. MySQL quotes identifiers with backticks and, in its default configuration, treats the backslash as an escape character inside string literals, so both the quote and the backslash must be handled. PostgreSQL and SQLite quote identifiers with double quotes and escape a literal quote only by doubling it. SQL Server uses square brackets. Booleans are a true type in PostgreSQL (TRUE/FALSE) but are typically represented as 1/0 elsewhere. Get any of these wrong and the statement either fails to parse or, worse, silently corrupts data — a name like O'Brien is the classic example that turns a naive generator's output into a syntax error.

This generator encodes the quoting and literal rules for four common databases and applies them consistently. It builds the column list from the union of keys so rows with different shapes still produce valid SQL, fills gaps with NULL, serializes nested structures to JSON strings for JSON or text columns, and offers batched multi-row inserts that are dramatically faster to execute than one statement per row while staying within configurable size limits. It is a convenience for trusted, ad-hoc data — seed files, fixtures, one-off imports — not a substitute for parameterized queries in application code: never assemble SQL by string-building untrusted input at runtime. Review the output, and for very large datasets prefer your database's bulk loader (COPY, LOAD DATA, .import) over generated inserts.

Common use cases

  • Seed data and fixtures. Turn a JSON array into INSERT statements for a migration or test database.
  • API response to table. Drop a captured JSON payload straight into a SQL table for analysis.
  • Cross-database moves. Re-quote the same data correctly for MySQL, Postgres, SQLite or SQL Server.
  • Quick imports. Generate batched multi-row inserts that load faster than one statement per row.

Frequently asked questions

How are different dialects quoted?

Identifiers are wrapped per database — backticks for MySQL, double quotes for PostgreSQL and SQLite, square brackets for SQL Server — and only when a name contains characters that require it. String literals double the single quote everywhere, and additionally escape backslashes for MySQL, whose default mode treats the backslash as an escape character.

What happens to nested objects, booleans and nulls?

A nested object or array is serialized to a JSON string and quoted as a literal, suitable for a JSON/JSONB or text column. Booleans become TRUE/FALSE in PostgreSQL and 1/0 in the other dialects. JSON null becomes the SQL NULL keyword (unquoted).

How are columns determined when rows differ?

The column list is the union of all keys across every object, in the order each key is first seen. Any row that lacks a given key gets NULL in that position, so an array of objects with slightly different shapes still produces aligned, valid INSERT statements.

What does rows-per-statement do?

With multi-row INSERT enabled, rows are grouped into batched VALUES (...),(...) statements of at most that many rows each. Smaller batches keep each statement under your database's packet size or bound-parameter limits; larger batches load faster. With multi-row disabled, every row becomes its own INSERT statement.

Is this safe against SQL injection?

It is a generator for trusted, ad-hoc data such as seed files and one-off imports, and you should review the output before running it. It is not a substitute for parameterized queries: application code must never build SQL by concatenating untrusted input at runtime. For very large loads, prefer your database's native bulk import (COPY, LOAD DATA, .import).