How to use the json to sql table generator
- Paste JSON records: an array of objects, or one object. A sample with several value types is loaded.
- Enter a table name and choose the database. Names are quoted for you in the style that database expects.
- Decide how nested objects are handled (stored as JSON text or flattened to columns), pick the INSERT style and the rows per statement, and optionally name a primary key column.
- Copy the SQL or download it as a .sql file, then review it before running it on a real database.
One record, one table
The JSON [{"id": 1, "name": "Ann"}] produces CREATE TABLE "people" with an id column of type INTEGER and a name column of type TEXT, followed by one INSERT with the values (1, 'Ann').
If a second record adds "active": true, the table gets an active BOOLEAN column and the first record gets NULL there, because the column list is the union of every key in first-seen order.
How column types are chosen
Each column is checked against every record. All whole numbers give INTEGER, or BIGINT when a value is larger than 2,147,483,647. Any decimal gives a double precision float. All booleans give BOOLEAN (BIT in SQL Server). Strings that are all real calendar dates such as 2024-02-29 give DATE, and strings that are all date and time stamps give TIMESTAMP. A column that mixes kinds, such as numbers and text, falls back to text, and numbers in it are written as quoted text.
A missing key or a null becomes NULL. Lists and objects that remain after your nesting choice are written as JSON text, in a JSON or JSONB column where the database has one.
Quoting and safety
Text is wrapped in single quotes with any single quote doubled, so O'Brien is written 'O''Brien'. For MySQL a backslash is doubled too, and SQL Server text gets the N prefix so Unicode letters survive. Table and column names are quoted with double quotes, backticks or square brackets, with any quote character inside the name doubled.
The output is a script for you to read. Types are guesses, money is better stored as NUMERIC than as a float, and a text primary key may need a length in your database. Run the script on a test copy first. Related tools are the CSV to SQL converter, the JSON schema generator and the test data generator.
Limits
The tool accepts up to the same text size as the JSON formatter, 100,000 records and 500 different keys. Numbers are read as ordinary JavaScript numbers, so integers beyond 15 digits can lose precision before the SQL is written. Nothing is uploaded and no database is contacted.
Assumptions and limits
- Column types are guesses from the values and should be reviewed.
- Decimal numbers become double precision floats, not exact NUMERIC types.
- Text is escaped by the rules of the database you pick, and other settings in your system may differ.
- SQL Server statements hold at most 1,000 rows each.
Frequently asked questions
How do I turn JSON into a SQL table?
Paste an array of objects, enter a table name and pick your database. The tool lists every key as a column, chooses a type for each and writes INSERT rows.
What happens to nested objects?
You choose. Store as JSON text keeps each object in one column. Flatten to columns turns {"addr": {"city": "X"}} into a column called addr_city.
Why is my ID column text?
If a column holds numbers in some records and text in others, it cannot be one number type, so it is written as text. Make the values the same kind to get a number column.
Can I choose a primary key?
Yes. Type the column name. It must exist in every record with no repeated values, or the tool explains the problem instead of writing a key that would fail.