DevGrill

JSON to SQL

Turn a JSON array into SQL INSERT statements, with an optional CREATE TABLE.

Runs in your browser

0 chars
0 chars

From JSON to rows in a table

Seeding a database, writing a migration or loading an API export into a table means turning JSON into INSERT statements, and doing it by hand is slow and error-prone: quotes inside strings, missing fields, booleans each database writes differently. Paste a JSON array of objects and get SQL that's ready to run.

Every key that appears in any object becomes a column, and missing values become NULL. Strings are escaped for the database you pick (PostgreSQL, MySQL, SQL Server, SQLite or standard SQL), names are quoted only when they need it, and numbers are written exactly as given, even IDs too big for JavaScript. Nested objects and arrays are stored as JSON text. Turn on CREATE TABLE for a table definition with column types worked out from the data.

How to use the JSON to SQL

  1. Paste a JSON array of objects. Each object is one row. A single object, or an object wrapping one array like {"data": [...]}, works too.

  2. Name the table and pick the database. Quoting, booleans and column types follow that database.

  3. Choose the statement style. One multi-row INSERT (faster to run) or one INSERT per row (easier to edit).

  4. Copy the SQL. Or open it in the SQL Formatter to tidy or minify it.

Tips

  • The CREATE TABLE types are a starting point worked out from your sample: check lengths, add a primary key and NOT NULL where you need them.
  • ISO dates like 2026-11-30 and timestamps like 2026-11-30T10:00:00Z become DATE and TIMESTAMP columns.
  • For thousands of rows, multi-row INSERTs are much faster. SQL Server allows at most 1,000 rows per statement, so it's split automatically.

Frequently asked questions

What happens to nested objects and arrays?

They're written as JSON text, which fits a JSON or JSONB column in PostgreSQL, a JSON column in MySQL, or a text column elsewhere.

Are my values escaped safely?

Yes. Single quotes are doubled, and for MySQL backslashes are escaped too, so values can't break out of their strings.

Can I go the other way, from a table to JSON?

For CSV exports, use the CSV Viewer or the JSON ↔ YAML ↔ CSV converter, which turn rows into JSON.

Is my data uploaded?

No. The SQL is generated in your browser.

Related tools