JSON to SQL Table

Generate SQL CREATE TABLE statements from JSON arrays. Infers types for PostgreSQL, MySQL, and SQLite. 100% client-side.

100% private · runs locally

Convert a JSON array of objects into a SQL CREATE TABLE statement. The generator scans every object in the array to infer the safest column types (e.g., choosing DOUBLE over INT if any decimals are found). Supports dialect-specific types for PostgreSQL, MySQL, and SQLite, including native JSON columns for nested data.

JSON input (Array or Object)
SQL Schema output SQL

Frequently asked questions

How are SQL column types inferred from JSON?

The tool scans all objects in the provided JSON array to find the most accommodating type for each key. For example, if a field is an integer in some objects but a float in others, it chooses a float type (like DOUBLE PRECISION). If it encounters nested objects or arrays, it falls back to a JSON/JSONB column or TEXT depending on the selected SQL dialect.

Does it support PostgreSQL, MySQL, and SQLite?

Yes. You can toggle between PostgreSQL, MySQL, and SQLite. The generator adjusts data types automatically: PostgreSQL gets DOUBLE PRECISION and JSONB, MySQL gets DOUBLE and JSON, and SQLite defaults to REAL and TEXT.

How does the tool handle nested JSON objects?

Unlike code generators that extract nested objects into separate classes, SQL databases store data in flat tables. Therefore, any nested objects or arrays in your JSON are mapped to a single JSON column (JSONB in Postgres, JSON in MySQL, TEXT in SQLite) so you can query them using database-specific JSON functions.

How are primary keys determined?

You can enable the "Add auto-increment PK" option. This will automatically inject a primary key column named "id" (e.g., id SERIAL PRIMARY KEY for Postgres or id INT AUTO_INCREMENT PRIMARY KEY for MySQL) at the beginning of the CREATE TABLE statement, ignoring any "id" field in your original JSON.

How can I insert this JSON data into my new table?

Once you have created the table with the generated schema, you can use a script (in Python, Node.js, etc.) to loop through your JSON array and execute SQL INSERT statements. Many modern databases and ORMs also support bulk inserting JSON directly using built-in copy commands or functions like json_populate_recordset in PostgreSQL.