Skip to content
ToolPlankDEV
Database Tools
100% In-Browser Execution

Updated:

JSON to SQL Converter

Paste JSON and get CREATE TABLE and INSERT statements as you type. This json to sql converter infers column types from every row, handles nested objects and arrays, and writes the syntax of your database. Nothing is uploaded.

Options:

JSON

Input
0 chars · 0 lines

SQL

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Summary, column types and notes

Rows, tables, the inferred column types and notes about the conversion appear here.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use JSON to SQL

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your JSON

    Paste an array of objects, an object that holds an array, or JSON Lines, or open a file. Example loads three users with nested data, and the sample buttons load flat orders, orders with line items and a JSON Lines log.

  2. 02

    Choose the database and the table name

    Pick MySQL, PostgreSQL, SQLite, SQL Server or Oracle, and type the table name. The syntax for quoting, strings, booleans, dates and types changes to match the database.

  3. 03

    Decide how nested data is stored

    Flatten turns objects into parent_child columns, JSON column keeps them as JSON text, and Child tables moves arrays of objects into their own tables with a foreign key. Choose a primary key, and whether existing rows are skipped or updated.

  4. 04

    Check the types and copy the SQL

    The panel lists the type chosen for every column. Replace any of them in the Column types box, then press Copy or Download to save data.sql and run it in your database client.

How to convert JSON to SQL

To convert JSON to SQL, each object in an array becomes a row and each key becomes a column. The tool reads all the rows first, decides one type for every column, writes a CREATE TABLE statement and then INSERT statements with the values. The result is plain SQL text that any client can run.

sql
[{"order_id":1001,"customer":"Acme","total":249.99,"paid":true,"placed":"2026-04-01"},
 {"order_id":1002,"customer":"Globex","total":80,"paid":false,"placed":"2026-04-02"}]

CREATE TABLE "orders" (
  "order_id" INTEGER NOT NULL,
  "customer" VARCHAR(32) NOT NULL,
  "total" NUMERIC(10, 2) NOT NULL,
  "paid" BOOLEAN NOT NULL,
  "placed" DATE NOT NULL
);

INSERT INTO "orders" ("order_id", "customer", "total", "paid", "placed") VALUES
  (1001, 'Acme', 249.99, TRUE, '2026-04-01'),
  (1002, 'Globex', 80, FALSE, '2026-04-02');

That is the PostgreSQL output. The conversion happens in your browser, as the Privacy Policy describes, so data that includes personal details never leaves your computer.

Column types come from every row

A type chosen from the first row alone often breaks on the tenth. The tool looks at all rows. A column of whole numbers becomes an integer, or a bigint when a value is larger than about two billion. Numbers with decimals become DECIMAL or NUMERIC with the precision and scale seen in the data. True and false become booleans, and strings that are all dates or all timestamps become DATE or a timestamp type.

  • Text becomes VARCHAR with room to grow, sized to the next step above twice the longest value, and TEXT, NVARCHAR(MAX) or CLOB when it is longer than 4,000 characters.
  • A column that mixes types, such as numbers and words, becomes text so no value is lost.
  • A column that is always null becomes a short text column, since the data says nothing about its type.
  • A column gets NOT NULL only when every row has a value for it.

To override any choice, write column=TYPE pairs in the Column types box, for example price=DECIMAL(10,2), code=CHAR(3). For a child table, write table.column.

Five dialects

The dialect controls everything that differs between databases.

  • MySQL uses backticks, TRUE and FALSE, DATETIME and JSON, and doubles backslashes inside strings because MySQL treats them as escapes.
  • PostgreSQL uses double quotes, BOOLEAN, TIMESTAMPTZ for values with a time zone and JSONB for nested data.
  • SQLite uses double quotes, stores booleans as 1 and 0 and dates as text, and caps one INSERT at 400 rows.
  • SQL Server uses square brackets, BIT for booleans, DATETIME2, an N prefix on text with accents or other scripts, and at most 1,000 rows per VALUES list.
  • Oracle uses double quotes, NUMBER and VARCHAR2, DATE and TIMESTAMP literals, CLOB for nested data and INSERT ALL for several rows.

Timestamps with a time zone offset are converted to UTC for MySQL, SQL Server and Oracle, whose column types do not keep the offset. PostgreSQL keeps the original text, and SQLite stores it as text.

Nested objects and arrays

Real JSON is rarely flat. Flatten objects turns {"address": {"city": "Lisbon"}} into a column named address_city. JSON column keeps the nested value as JSON text in one column, which suits a database with JSON support. Arrays of plain values stay in a JSON column in both of those modes.

Child tables go further. An array of objects such as order items becomes its own table, named after the parent and the key, with a foreign key to the parent id. Rows get numbered ids, so the links are exact, and the parent table is written before its children.

sql
CREATE TABLE "orders_items" (
  "id" INTEGER NOT NULL,
  "orders_id" INTEGER NOT NULL,
  "sku" TEXT NOT NULL,
  "qty" INTEGER NOT NULL,
  PRIMARY KEY ("id"),
  FOREIGN KEY ("orders_id") REFERENCES "orders" ("id")
);

Primary keys, upserts and batches

With Primary key set to Auto, a column named id becomes the primary key when its values are unique. Add id column always numbers the rows, and None writes no key. Existing rows decides what happens when a key already exists in the table: Insert only fails, Ignore skips the row and Update overwrites it.

sql
INSERT INTO "users" ("id", "name") VALUES
  (1, 'Ana'),
  (2, 'Ben')
ON CONFLICT ("id") DO UPDATE SET "name" = EXCLUDED."name";

The statement differs by database: INSERT IGNORE and ON DUPLICATE KEY UPDATE for MySQL, ON CONFLICT for PostgreSQL and SQLite, and MERGE for SQL Server and Oracle. Rows per INSERT sets the batch size. Wrap in a transaction adds BEGIN and COMMIT, so a failed import changes nothing.

Input shapes and limits

  • An object that wraps an array is read automatically. The largest array of objects is used, or type a path such as data.items.
  • JSON Lines and several JSON documents are read as one row each.
  • A value that is not an object is stored in a column named value.
  • Numbers larger than 9,007,199,254,740,991 can lose digits when the JSON is read, so the tool warns you. Write such ids as strings in the JSON.
  • The input can be up to 2 million characters. The tool does not connect to a database or run the SQL.

Review the SQL before running it, especially with Drop table first, which deletes existing data. To go the other way, use SQL to JSON. JSON Schema Generator describes the same data as a schema, and JSON to YAML converts it to YAML.

Frequently Asked Questions

Technical Q&A for JSON to SQL

Common questions about edge cases, character encoding, and privacy guarantees.

Paste your JSON array, choose the database and the table name, and copy the CREATE TABLE and INSERT statements from the result.

MySQL, PostgreSQL, SQLite, SQL Server and Oracle. Quoting, strings, booleans, dates, types and multi-row inserts follow each one.

It reads every row. Whole numbers, decimals, booleans, dates and timestamps get matching types, and a column that mixes types becomes text. You can replace any type.

Choose Flatten objects to make parent_child columns, JSON column to keep nested values as JSON, or Child tables to split arrays of objects into their own tables with a foreign key.

Yes. Turn off Write CREATE TABLE and only the INSERT statements are written, for a table that already exists.

Set Existing rows to Update duplicates and give the data a unique id column. The tool writes ON DUPLICATE KEY UPDATE, ON CONFLICT or MERGE for your database.

Choose SQL Server, copy the script and run it in SQL Server Management Studio or Azure Data Studio. Batches are limited to 1,000 rows, as SQL Server requires.

Single quotes are doubled, and MySQL backslashes are escaped. Text with accents gets an N prefix for SQL Server. Run the script on a test database first.

Yes. Paste one object per line, or several documents one after another, and each becomes a row.

No. The SQL is built in your browser, so private data stays on your computer.