JSON to SQL

CREATE TABLE and INSERT statements for Postgres, MySQL, SQL Server or SQLite.

About & FAQ ↓
JSON array
Waiting for input.
SQL

Values are inlined as literals with quotes escaped — fine for seeding and fixtures, but use parameterised queries for anything driven by untrusted input.

Reference
JSON to SQL

About the JSON to SQL generator

Getting a JSON export into a database usually means writing the DDL by hand. This infers column types from every row rather than the first — a column holding 1, 2 and 3.5 becomes decimal, and a column that is ever missing or null becomes nullable — then emits a CREATE TABLE and the INSERT statements to load it, quoted correctly for your dialect.

01

Four dialects

PostgreSQL, MySQL, SQL Server and SQLite, each with correct quoting, types and boolean literals.

02

Types from every row

A column holding 1, 2 and 3.5 becomes decimal; a column ever missing becomes nullable.

03

CREATE plus INSERT

Table definition and the statements to load it, chunked for large sets.

04

Nested data handled

Objects and arrays are stored as JSON text columns, which is what these databases want anyway.

How to use it

  1. Paste an array of JSON objects.
  2. Pick the dialect and table name, and whether columns are converted to snake_case.
  3. Copy the SQL, or download it as a .sql file.

Questions

Which databases are supported?

PostgreSQL, MySQL, SQL Server and SQLite. Identifier quoting, boolean literals and type names follow each dialect — JSONB for Postgres, JSON for MySQL, NVARCHAR(MAX) for SQL Server, TEXT for SQLite.

What happens to nested objects and arrays?

They are stored as JSON text in a single column, which is what all four databases would have you do anyway. Flatten them first with the CSV tool if you want separate columns.

Is the generated SQL safe to run?

Values are inlined as escaped literals, which is fine for seeding and fixtures. Do not build a pipeline that inlines untrusted input this way — use parameterised queries for anything user-driven.