Output will appear here
Output will appear here
Paste a JSON array of objects and get a CREATE TABLE statement plus one INSERT per row. Column types come from every row, not just the first: BIGINT, DOUBLE PRECISION, BOOLEAN, TIMESTAMP, DATE, TEXT, and JSON for nested objects and arrays. The SQL is ANSI with double-quoted identifiers. It runs as written on PostgreSQL, SQLite and DuckDB.
By Ankit Aglawe · Updated · Runs entirely in your browser
trial_ends is null in one row and missing in another, so it is the only column without NOT NULL, and both rows get NULL. plan repeats two values, so it gets a CHECK (... IN ('pro', 'free')). The apostrophe in o'neil is escaped as ''. mrr mixes 0 and 588.5, so it is DOUBLE PRECISION.
[
{ "id": 101, "email": "[email protected]", "plan": "pro", "seats": 5, "mrr": 245.0, "trial_ends": null, "signed_up": "2024-03-02T09:14:00Z" },
{ "id": 102, "email": "[email protected]", "plan": "free", "seats": 1, "mrr": 0, "trial_ends": "2024-04-01", "signed_up": "2024-03-05T17:40:12Z" },
{ "id": 103, "email": "o'[email protected]", "plan": "pro", "seats": 12, "mrr": 588.5, "signed_up": "2024-03-07T08:01:55Z" },
{ "id": 104, "email": "[email protected]", "plan": "free", "seats": 1, "mrr": 0, "trial_ends": "2024-04-09", "signed_up": "2024-03-09T12:30:00Z" }
]-- Generated by JSONConvert
-- ANSI SQL: runs as written on PostgreSQL, SQLite and DuckDB.
-- MySQL/MariaDB: SET sql_mode = 'ANSI_QUOTES,NO_BACKSLASH_ESCAPES'; first.
CREATE TABLE "data" (
"id" BIGINT NOT NULL,
"email" TEXT NOT NULL,
"plan" TEXT NOT NULL CHECK ("plan" IN ('pro', 'free')),
"seats" BIGINT NOT NULL,
"mrr" DOUBLE PRECISION NOT NULL,
"trial_ends" DATE,
"signed_up" TIMESTAMP NOT NULL
);
INSERT INTO "data" ("id", "email", "plan", "seats", "mrr", "trial_ends", "signed_up")
VALUES (101, '[email protected]', 'pro', 5, 245, NULL, '2024-03-02T09:14:00Z');
INSERT INTO "data" ("id", "email", "plan", "seats", "mrr", "trial_ends", "signed_up")
VALUES (102, '[email protected]', 'free', 1, 0, '2024-04-01', '2024-03-05T17:40:12Z');
INSERT INTO "data" ("id", "email", "plan", "seats", "mrr", "trial_ends", "signed_up")
VALUES (103, 'o''[email protected]', 'pro', 12, 588.5, NULL, '2024-03-07T08:01:55Z');
INSERT INTO "data" ("id", "email", "plan", "seats", "mrr", "trial_ends", "signed_up")
VALUES (104, '[email protected]', 'free', 1, 0, '2024-04-09', '2024-03-09T12:30:00Z');A single object becomes one row. shipping and lines are not split into child tables; they become JSON columns holding the compact JSON text. coupon is always null, so it falls back to a nullable TEXT column.
{
"order_id": "A-1042",
"placed_at": "2024-06-18T14:22:05Z",
"paid": true,
"total": 74.9,
"shipping": { "city": "Leeds", "postcode": "LS1 4AP" },
"lines": [
{ "sku": "MUG-01", "qty": 2 },
{ "sku": "TEE-L", "qty": 1 }
],
"coupon": null
}-- Generated by JSONConvert
-- ANSI SQL: runs as written on PostgreSQL, SQLite and DuckDB.
-- MySQL/MariaDB: SET sql_mode = 'ANSI_QUOTES,NO_BACKSLASH_ESCAPES'; first.
CREATE TABLE "data" (
"order_id" TEXT NOT NULL,
"placed_at" TIMESTAMP NOT NULL,
"paid" BOOLEAN NOT NULL,
"total" DOUBLE PRECISION NOT NULL,
"shipping" JSON NOT NULL,
"lines" JSON NOT NULL,
"coupon" TEXT
);
INSERT INTO "data" ("order_id", "placed_at", "paid", "total", "shipping", "lines", "coupon")
VALUES ('A-1042', '2024-06-18T14:22:05Z', TRUE, 74.9, '{"city":"Leeds","postcode":"LS1 4AP"}', '[{"sku":"MUG-01","qty":2},{"sku":"TEE-L","qty":1}]', NULL);Every code generator on this site is run on the same awkward input: a 64-bit id, a float written as 1.0, a null, a date string, a reserved word as a key, an empty array, a nested array and an array of objects whose keys differ. This is the exact output for SQL, generated when the page was built.
{
"id": 9007199254740993,
"price": 19.99,
"ratio": 1.0,
"deleted_at": null,
"created_at": "2024-01-15T10:30:00Z",
"class": "premium",
"tags": [],
"matrix": [[1, 2], [3, 4.5]],
"items": [{ "sku": "A1", "qty": 1 }, { "sku": "B2", "qty": 2, "note": "gift" }]
}-- Generated by JSONConvert
-- ANSI SQL: runs as written on PostgreSQL, SQLite and DuckDB.
-- MySQL/MariaDB: SET sql_mode = 'ANSI_QUOTES,NO_BACKSLASH_ESCAPES'; first.
CREATE TABLE "data" (
"id" BIGINT NOT NULL,
"price" DOUBLE PRECISION NOT NULL,
"ratio" BIGINT NOT NULL,
"deleted_at" TEXT,
"created_at" TIMESTAMP NOT NULL,
"class" TEXT NOT NULL,
"tags" JSON NOT NULL,
"matrix" JSON NOT NULL,
"items" JSON NOT NULL
);
INSERT INTO "data" ("id", "price", "ratio", "deleted_at", "created_at", "class", "tags", "matrix", "items")
VALUES (9007199254740992, 19.99, 1, NULL, '2024-01-15T10:30:00Z', 'premium', '[]', '[[1,2],[3,4.5]]', '[{"sku":"A1","qty":1},{"sku":"B2","qty":2,"note":"gift"}]');The output is ANSI SQL. Every table and column name is wrapped in double quotes, so keys like class, order or user never collide with a reserved word. PostgreSQL, SQLite and DuckDB accept it unchanged. On MySQL or MariaDB, run SET sql_mode = 'ANSI_QUOTES,NO_BACKSLASH_ESCAPES'; first, as the header comment says.
A column gets NOT NULL only when the key is in every row and never null. A key missing from a row is inserted as NULL. A column that is null in every row, like deleted_at above, has no type evidence and becomes a nullable TEXT.
Objects and arrays are stored in a JSON column as a quoted JSON string, for example '[[1,2],[3,4.5]]' for matrix and '[]' for the empty tags. Nothing is flattened or normalized. Query them with ->> in PostgreSQL or json_extract() in SQLite, or change the type to JSONB on Postgres.
Whole numbers become BIGINT and any column with a decimal becomes DOUBLE PRECISION. The browser reads 1.0 as 1, so ratio is BIGINT. The browser also rounds integers above 2^53, so the INSERT above carries 9007199254740992 for an id of 9007199254740993. If your ids are that large, export them as strings.
Full ISO 8601 date-times become TIMESTAMP and plain dates become DATE. The value is inserted exactly as written, offset included. PostgreSQL TIMESTAMP ignores the Z or offset; change the column to TIMESTAMPTZ if you need it kept.
A key that holds a number in one row and a string in another becomes TEXT, and every value is quoted to match. Single quotes in strings are doubled (''), which is the standard escape on every engine.
An array like [1, 2, 3] becomes a one-column table named "value" with one row per element. An empty array, or input with no object keys, produces a comment instead of a CREATE TABLE with no columns.
| JSON value | SQL type | INSERT literal |
|---|---|---|
| whole number | BIGINT | 42 |
| number with a fraction | DOUBLE PRECISION | 19.99 |
| true / false | BOOLEAN | TRUE / FALSE |
| ISO 8601 date-time | TIMESTAMP | '2024-01-15T10:30:00Z' |
| ISO date | DATE | '2024-01-15' |
| string | TEXT | 'o''neil' |
| repeated small set of strings | TEXT CHECK (... IN (...)) | |
| object or array | JSON | '{"city":"Leeds"}' |
| null or missing key | column stays nullable | NULL |
| mixed types | TEXT | quoted |
Enter a JSON array of objects where each object is a table row. Every element is read, not just the first, so a key that only appears in the last row still becomes a column.
The output is a CREATE TABLE statement followed by one INSERT per object. Column types are BIGINT, DOUBLE PRECISION, BOOLEAN, TEXT, DATE, TIMESTAMP or JSON, chosen as the widest type that holds every value seen rather than a width guessed from the first row. A key present on every row and never null is marked NOT NULL.
Copy the SQL or download it as a .sql file. It runs as written on PostgreSQL, SQLite and DuckDB. On MySQL or MariaDB, run SET sql_mode = 'ANSI_QUOTES,NO_BACKSLASH_ESCAPES'; first, which the generated header repeats.
Paste a JSON array of objects. The output has a CREATE TABLE followed by one INSERT per object, with columns in the order keys first appear. Copy it into psql, the sqlite3 shell or any SQL client.
It is ANSI SQL with double-quoted identifiers. It runs unchanged on PostgreSQL, SQLite and DuckDB. MySQL and MariaDB need ANSI_QUOTES turned on first.
The table is always called "data". Find and replace "data" in the output with your table name.
No. Nested objects and arrays go into a JSON column as JSON text. If you need child tables with foreign keys, flatten the JSON first or split it with a query after loading.
No. The generator cannot know which key is unique, so it adds no PRIMARY KEY or index. Add one to the CREATE TABLE before running it.
Yes, but you get one INSERT per row. Wrap them in BEGIN; and COMMIT; so the database does not commit after every statement.
No. The SQL is generated in your browser, so a customer export never leaves your machine.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.