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.
[{"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.
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.
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.