JSON to SQL CREATE TABLE
Turn a JSON array of records into a CREATE TABLE statement with inferred column types, nullability and lengths. Emits MySQL, PostgreSQL or SQLite dialects.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
Schema inference from real records
The fastest way to land a JSON export in a relational database is to let the data describe itself. Given a sample of records, the shape is already there: which keys appear, which are sometimes missing, whether a numeric column ever holds a fraction, and how long the longest string actually is. Writing that out by hand is tedious and error prone, and the mistakes surface later as truncated values or a column typed INT that receives an identifier past two billion.
What is inferred and how
Every key across every record is collected, so a field present in only some records still gets a column and is marked nullable. Numbers are split into integer and decimal, and integers are widened to BIGINT once a value passes the 32 bit range. Strings are measured, and the declared length is rounded up to the next sensible power of two with headroom, because the longest value in a sample is rarely the longest value in production. Values that parse as ISO 8601 become date or timestamp columns, booleans become the dialect appropriate boolean type, and nested objects and arrays become JSON columns rather than being flattened.
Treat it as a first draft
Inference cannot know your keys, your indexes or your collation. It will guess a primary key when it finds a field named id that is unique across the sample, and it will say so. Review the lengths, add the indexes your queries need, and decide on character sets before running the statement against anything that matters.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
How many records should I paste?
As many as you can. Types and lengths are inferred from the sample, so ten records will under size string columns that a thousand records would size correctly. The tool reports how many records it read so you can judge confidence.
Why is a numeric field typed as text?
Because at least one record held a non numeric value for that key, such as an empty string used in place of null. The tool widens to the safest type that holds every observed value rather than picking the type that fits most of them.
How are nested objects handled?
They become a JSON column: the JSON type in MySQL and SQLite, and JSONB in PostgreSQL. Flattening nested structures into columns needs decisions about naming and cardinality that only you can make.
Does it detect a primary key?
It suggests one when a field named id, uuid or _id is present in every record and unique across the sample. That is a heuristic, not a guarantee, and it is clearly labelled as a suggestion in the output.
Are the generated lengths safe for production?
They are padded above the longest observed value, but a sample is a sample. For user supplied free text prefer TEXT over a guessed VARCHAR, and remember that MySQL counts index bytes rather than characters under utf8mb4.
Privacy & Security
Everything runs in your browser; nothing is uploaded.
How to Use
Paste an array of JSON objects, choose a dialect and table name, then generate the DDL.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.