01What is JSON to SQL CREATE?
You have a sample record from an API or a log, and you need a table to put it in. This tool reads one JSON object and writes a CREATE TABLE statement for PostgreSQL, MySQL or SQLite. Every top-level key becomes a column. CamelCase keys turn into snake_case, so createdAt becomes created_at and userName becomes user_name. Column types come from the sample values, one key at a time. Booleans map to BOOLEAN, or INTEGER on SQLite. Whole numbers become INTEGER, and anything past the 32-bit limit of 2147483647 becomes BIGINT. Decimals get DECIMAL(10, 2), or REAL on SQLite. A string shaped like an ISO 8601 timestamp becomes TIMESTAMP WITH TIME ZONE on Postgres and DATETIME on MySQL. A plain YYYY-MM-DD string becomes DATE. UUID strings get the native UUID type on Postgres and CHAR(36) on MySQL. Other strings are sized by the sample length: VARCHAR(50), VARCHAR(255), then TEXT. SQLite simply gets TEXT for all of these, which matches its type affinity rules in the official SQLite docs. Arrays and nested objects become JSONB on Postgres, JSON on MySQL and TEXT on SQLite. A key named id becomes the primary key. If its value is an integer, Postgres gets SERIAL, MySQL gets AUTO_INCREMENT and SQLite gets AUTOINCREMENT. Scalar values that aren't null get NOT NULL. A null sample gets VARCHAR(255) with no constraint, since the real type is unknown. Column names are always quoted, with backticks on MySQL and double quotes elsewhere. If userId and user_id both appear, the second column is renamed user_id_2 so the statement still runs. Here's a quick example. Feed it {"views": 3000000000, "orderId": 5, "born": "1990-04-01"} on Postgres. You get views BIGINT NOT NULL, order_id INTEGER NOT NULL and born DATE NOT NULL. Under a Suggested indexes comment you also get CREATE INDEX "idx_my_table_order_id", because keys ending in Id or _id look like foreign keys. Keys named email, or containing lowercase slug, get an index too. JSON columns and MySQL TEXT columns are skipped there, since they need extra options to be indexed. Now the honest limits. It sees one row, so NOT NULL and VARCHAR sizes reflect that sample and nothing more. A top-level array is rejected with an error, so paste one element instead. Nested objects are stored as a JSON column, not split into child tables. And the SQL is built locally in your tab from the text you paste, with no server round trip.
Backend developers and data engineers who need a first-draft table definition for JSON they already have in hand. The tool runs entirely in your browser, so your data never leaves your device.
02How to use JSON to SQL CREATE
- Pick PostgreSQL, MySQL or SQLite from the Dialect dropdown.
- Type a name in the Table field. Spaces and symbols become underscores.
- Paste one JSON object, representing a single row, into JSON Input.
- Read the CREATE TABLE statement and any Suggested indexes in SQL Output.
- Copy the SQL, widen sizes or relax NOT NULL where your real data needs it, then run it.
03Worked examples
- Input:
{"id":1,"userName":"ann","created_at":"2024-01-05T10:00:00Z","price":9.99,"active":true} (Dialect: PostgreSQL, Table: users) - Result:
CREATE TABLE IF NOT EXISTS "users" ( "id" SERIAL PRIMARY KEY, "user_name" VARCHAR(50) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, "price" DECIMAL(10, 2) NOT NULL, "active" BOOLEAN NOT NULL ); - An integer id becomes SERIAL PRIMARY KEY, userName becomes user_name, and the ISO 8601 string is typed as a timestamp.
- Input:
Same JSON (Dialect: MySQL) - Result:
CREATE TABLE IF NOT EXISTS `users` ( `id` INTEGER PRIMARY KEY AUTO_INCREMENT, `user_name` VARCHAR(50) NOT NULL, `created_at` DATETIME NOT NULL, `price` DECIMAL(10, 2) NOT NULL, `active` BOOLEAN NOT NULL ); - MySQL gets backtick quoting, AUTO_INCREMENT and DATETIME.
- Input:
{"id":1,"tags":["a"],"meta":{"k":1}} (Dialect: SQLite, Table: users) - Result:
CREATE TABLE "users" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "tags" TEXT, "meta" TEXT ); - SQLite stores arrays and nested objects as TEXT. They get no NOT NULL, and the SQLite output has no IF NOT EXISTS.
- Input:
{"id":"550e8400-e29b-41d4-a716-446655440000","orderId":5,"email":"[email protected]","born":"1990-04-01","views":3000000000,"note":null} (PostgreSQL, Table: Order Items) - Result:
CREATE TABLE IF NOT EXISTS "order_items" ( "id" UUID PRIMARY KEY, "order_id" INTEGER NOT NULL, "email" VARCHAR(50) NOT NULL, "born" DATE NOT NULL, "views" BIGINT NOT NULL, "note" VARCHAR(255) ); -- Suggested indexes: CREATE INDEX "idx_order_items_order_id" ON "order_items" ("order_id"); CREATE INDEX "idx_order_items_email" ON "order_items" ("email"); - UUID id, BIGINT past the 32-bit range, DATE for a plain date, and a nullable VARCHAR(255) for null. The table name is cleaned to order_items.
- Input:
{"userId":1,"user_id":2} (Dialect: MySQL, Table: profiles) - Result:
CREATE TABLE IF NOT EXISTS `profiles` ( `user_id` INTEGER NOT NULL, `user_id_2` INTEGER NOT NULL ); -- Suggested indexes: CREATE INDEX `idx_profiles_user_id` ON `profiles` (`user_id`); CREATE INDEX `idx_profiles_user_id_2` ON `profiles` (`user_id_2`); - Both keys map to user_id, so the second gets a _2 suffix.
- Input:
[{"id":1,"email":"[email protected]"},{"id":2,"email":null}] - Result:
Input must be a JSON object (not an array or primitive) - One object equals one row. Paste a single element of the array instead.
04Common use cases
- Creating a Postgres table to store incoming Stripe or GitHub webhook payloads with the raw body in a JSONB column
- Spinning up a SQLite schema for a prototype from a single API response you saved to disk
- Turning a MongoDB document into a first draft of a relational migration
- Writing the first CREATE TABLE for a Knex, Flyway or raw SQL migration from a sample record
- Comparing how the same record maps to column types across Postgres, MySQL and SQLite
- Getting quick index suggestions for foreign-key style columns like order_id and user_id
05Tips
- DECIMAL(10, 2) suits prices but truncates coordinates and ratios. Widen the scale, for example DECIMAL(9, 6) for latitude.
- A null in the sample gives VARCHAR(255) with no type hint. Swap in a real sample value to get the right column type.
- Only a key named exactly id becomes the primary key. A key like userId is treated as a foreign key and gets an index suggestion instead.
- The slug check is case sensitive, so postSlug is not indexed while post_slug is. Add that index by hand if you need it.
- MySQL DATETIME stores no time zone. Convert ISO timestamps such as 2024-01-15T10:30:00Z to UTC 'YYYY-MM-DD HH:MM:SS' before inserting.
06Related concepts
DDL, Primary key, JSONB, Database indexes, Schema design.
Frequently Asked Questions
What is JSON to SQL CREATE?
JSON to SQL CREATE is a free, browser-based developer tool on AIDToolStack. Convert JSON to SQL CREATE TABLE It requires no installation or sign-up and works entirely in your browser.
Is JSON to SQL CREATE free to use?
Yes. No sign-up, no fees and no usage cap.
Does JSON to SQL CREATE store my data?
No. It runs in your browser; nothing is uploaded.