Output will appear here
Output will appear here
Convert JSON to SQL CREATE TABLE and INSERT INTO statements with this free online tool. Column types are inferred from every row rather than the first, identifiers are quoted so reserved words and spaces do not break the script, and types are chosen wide enough to hold the data: BIGINT for 64-bit ids, DOUBLE PRECISION for decimals, TEXT for strings of any length. The output is ANSI SQL and runs on PostgreSQL, SQLite and DuckDB as written, and on MySQL with ANSI_QUOTES set.
Try Convert All - paste JSON once, see TypeScript, Go, YAML, and 15 more formats instantly.
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 into the converter. Each object becomes an INSERT INTO statement where keys map to column names and values map to correctly quoted SQL literals, and the matching CREATE TABLE statement is generated above them so you can run the whole script in one step.
Integers map to BIGINT, non-integer numbers to DOUBLE PRECISION, booleans to BOOLEAN, strings to TEXT, ISO dates and timestamps to DATE and TIMESTAMP, and nested objects or arrays to JSON. Each type is the widest one that holds every value observed for that key. No VARCHAR length or DECIMAL scale is guessed, because JSON carries no width information and a guessed width is one some later row overflows.
JSON does not say how wide a number is. A 64-bit identifier is one of the most common things in a real payload and it does not fit INT, so a generator that reads 1 in the first row and writes INT produces a table that rejects the rest of the file. BIGINT holds every integer JSON can carry. Narrow it by hand if you know the range.
The output is ANSI SQL and runs as written on PostgreSQL, SQLite and DuckDB. Identifiers are delimited with double quotes, which is the SQL standard, so MySQL and MariaDB need SET sql_mode = 'ANSI_QUOTES,NO_BACKSLASH_ESCAPES'; first — the generated header says so. Quoting is unconditional because reserved words differ per engine: order, user, desc, group and key are each reserved somewhere, and an unquoted one is a syntax error.
Nested objects and arrays are serialized and stored in JSON columns, which PostgreSQL, MySQL and SQLite all accept as a type name. Change the column to JSONB on PostgreSQL if you want the binary representation and its indexes.
When a text column takes only a small set of values and repeats them, that is a closed set rather than free text, and CHECK (col IN (...)) is how SQL expresses it. The rule is deliberately conservative — a set of values that never repeat is treated as free text — because a wrong constraint rejects data the source document contained.
Yes. The converter generates one INSERT statement per row, which is fine for small to medium datasets. For very large imports, rewrite the output as multi-row INSERT syntax or use your database COPY or LOAD DATA command.