Generate CREATE TABLE and INSERT statements from a JSON array.
The JSON to SQL converter turns a JSON array of objects into an optional CREATE TABLE statement plus INSERT statements for MySQL, PostgreSQL or SQLite. Column types are inferred from the values and strings are escaped for the chosen dialect. It is handy for seeding a database from an API export or a fixture file.
A JSON array of objects is a list of records, which maps naturally onto a table: each object is a row and each key is a column. To load it into a relational database you need a CREATE TABLE statement with a type for every column and INSERT statements with correctly quoted values. The tool collects every key found in any object as a column, in order of first appearance, and fills missing keys with NULL. Types are inferred by looking at all values in a column: whole numbers become integers, decimals become floating-point, true and false become booleans, strings become text, and nested objects or arrays are stored as JSON text. Each database writes these types and booleans differently, so the Dialect option changes the type names, identifier quoting and boolean literals.
As JSON text in a single column: type JSON in MySQL, JSONB in PostgreSQL and TEXT in SQLite. The value is written as a quoted JSON string.
The set of columns is the union of keys across all objects. Where an object has no value for a column, NULL is inserted.
Yes. Table and column names are quoted (backticks for MySQL, double quotes for PostgreSQL and SQLite), and string values have single quotes doubled. MySQL strings also have backslashes escaped.
If a column mixes numbers with strings or booleans, the tool cannot pick a numeric type and uses a text type. Clean the data so each key has one type.
Review it first. The tool builds statements from your data without knowing your schema, and it does not add keys, constraints or transactions.
No. The SQL is generated in the page and the input is not sent anywhere.