Convert JSON to SQL Statements
When an API or application gives you records as JSON but a database needs rows, a converter can draft the table definition and insert statements. This JSON to SQL converter supports SQLite, MySQL, and PostgreSQL. It infers columns and types from the input, lets you choose a table name, and can generate a CREATE TABLE statement, an INSERT statement, or both.
Paste valid JSON or open a JSON file, select the database dialect, and review the generated SQL before using it. The conversion runs in your browser; this tool creates SQL text but does not connect to or change a database.
How to Convert JSON to SQL
- Paste JSON into the input area, choose Open JSON, or load the sample.
- Select SQLite, MySQL, or PostgreSQL to match the database where the SQL will run.
- Enter a table name using letters, numbers, or underscores. It must begin with a letter or underscore.
- Choose whether to include the table definition, insert data, and flatten nested objects. At least one SQL statement option must be selected.
- Select Generate SQL. Check the SQL, row and column counts, and inferred types before copying or downloading the output.
If the input is rejected as invalid JSON, check its syntax with the JSON Validator and try again.
Example: JSON Records to PostgreSQL
This example uses an array of customers, the PostgreSQL dialect, the table name customers, and both statement options. With flattening enabled, profile.city becomes a column. The array in tags stays JSON text in a text column.
Input JSON
[
{"id": 101, "name": "Mina Patel", "active": true, "profile": {"city": "Pune"}, "tags": ["beta", "email"]},
{"id": 102, "name": "O'Neil", "active": false, "profile": {"city": "Austin"}, "tags": ["new"]}
]
Generated SQL
CREATE TABLE "customers" (
"id" INTEGER,
"name" TEXT,
"active" BOOLEAN,
"profile.city" TEXT,
"tags" TEXT
);
INSERT INTO "customers" ("id", "name", "active", "profile.city", "tags")
VALUES
(101, 'Mina Patel', TRUE, 'Pune', '["beta","email"]'),
(102, 'O''Neil', FALSE, 'Austin', '["new"]');
The generated values match the selected PostgreSQL dialect. The apostrophe in O'Neil is doubled inside the SQL string literal. Select another dialect to generate its corresponding identifier quotes, boolean values, and column types.
Supported SQL Dialects and Inferred Types
The converter chooses a type from the values observed in each column. Common mappings include:
| JSON values | SQLite | MySQL | PostgreSQL |
|---|---|---|---|
| Whole numbers | INTEGER | INTEGER | INTEGER |
| Decimal numbers | REAL | DOUBLE | DOUBLE PRECISION |
| Booleans | INTEGER (1 or 0) | TINYINT(1) | BOOLEAN |
| Strings and nested values | TEXT | TEXT | TEXT |
When a column mixes strings with numbers, or mixes booleans with another type, it is treated as text so the different values can be represented. Whole numbers and decimals together use the dialect’s decimal-number type. Nulls and missing fields are emitted as NULL; they do not determine a column type. If a column contains only nulls, its inferred type is text.
How JSON Structure Maps to SQL Columns
Arrays of objects
An array of objects is the clearest input for a relational table: each object becomes a row and property names across the records become columns. A property missing from a particular object is inserted as NULL. One INSERT statement contains all input rows, rather than separate inserts for each record.
Single objects and primitive values
A single object becomes one row. A top-level primitive, or each primitive in a top-level array, is placed in a column named value. An array of arrays is treated as values in that column; it is not automatically expanded into several SQL columns.
Nested objects and arrays
With Flatten nested objects enabled, nested objects are expanded into dotted column names such as profile.city. Turn flattening off to keep each nested object as JSON text in one column. Arrays inside records are also stored as JSON text; the converter does not expand array items into rows or create related tables.
If an API response wraps a list under a key such as data or results, this tool treats the wrapper as a record and stores the array in that field as JSON text. It does not automatically unwrap the inner array. Extract the list of records first if you want each item to become a database row.
Review the SQL Before Running It
- Check the inferred schema: Type inference uses the values provided, not a database schema or business rules. It does not add primary keys, unique constraints,
NOT NULLconstraints, indexes, defaults, or relationships between tables. - Keep exact identifiers: JSON numbers are parsed as JavaScript numbers. Very large integers can lose precision before SQL is generated. If an ID, account number, or other value must preserve every digit, represent it as a JSON string.
- Check the destination: Confirm the table name is available and that the selected dialect matches the database version and configuration where you will run the SQL.
- Plan for large batches: All records are written into one multi-row
INSERTstatement. For a large export, split the input into smaller batches if your database has query or packet-size limits. - Review values and permissions: Inspect the generated statements and run them in the intended database or a safe development environment. The converter does not execute or validate SQL against your database.
Identifiers are quoted for the selected dialect, and single quotes inside string values are escaped. Those safeguards help create well-formed output, but inferred SQL is still a starting point: review it for your schema, database rules, and data requirements before execution.
Frequently Asked Questions
Which SQL databases does the converter support?
It generates SQL for SQLite, MySQL, and PostgreSQL. Choose the dialect that matches your destination database before generating the statements.
Can I generate only INSERT statements?
Yes. Turn off Include CREATE TABLE and leave Include INSERT statements on. You can also generate only a table definition, or include both. At least one option must remain selected.
How are nested JSON objects converted?
By default, nested objects are flattened into dotted column names such as profile.city. Turn off flattening to store each object as JSON text in a column. Nested arrays remain JSON text either way.
What happens to null or missing properties?
They become SQL NULL. If a field is missing from one object but present in others, the column is still included and the missing row receives NULL.
Does the tool connect to my database?
No. It generates SQL text in your browser for you to review, copy, or download. You choose where and whether to run it.
Is the generated SQL ready to run without changes?
It is a useful starting point, but review the inferred types, table name, null behavior, large numeric values, and database-specific requirements first. The converter does not know your existing schema or constraints.
Related JSON Tools
Use the JSON Validator to check input syntax, the JSON Formatter to make records easier to inspect, or the JSON to CSV Converter and JSON to Excel Converter when you need spreadsheet output.