JSON to SQL Converter
This JSON to SQL converter turns an array of objects into INSERT statements, with columns taken from the object keys in the order they first appear. Values are escaped for SQL so apostrophes in your data cannot break or inject a statement, and JSON types map across directly: numbers and booleans stay unquoted and null becomes NULL. Nested objects and arrays are expanded into dot and index columns by default; turn expansion off to keep each nested value in one column as compact JSON, which is what you want for a JSON or JSONB column. You can name the target table, pick the identifier quoting style, batch the rows into one statement and prepend a CREATE TABLE with inferred types.
How it works
An array of objects becomes one INSERT per object, with columns taken from the keys in the order they first appear. Values are escaped for SQL, so apostrophes in your data cannot break or inject a statement.
Nested objects and arrays are expanded into dot and index columns by default. Turn expansion off to store each nested value in one column as compact JSON instead, which suits a JSON or JSONB column.
The conversion runs entirely in your browser — nothing you paste or upload is sent to a server.
How to convert JSON to SQL
- Paste an array of objects into the input on the left.
- Set the table name and pick the identifier quoting your database uses.
- Copy the statements, or download them as a
.sqlfile.
Nested data: two reasonable answers
An API response rarely has the flat shape a relational table wants. There are two sensible things to do with a nested object, and which one is right depends on your schema.
Expand it — the default — turns address.city and tags[0] into their own
columns. Use this when the destination is a normal table with one column per field, and you want the values
queryable and indexable.
Keep it whole — turn expansion off — writes each nested value into a single column as compact
JSON. Use this when the destination column is JSON or JSONB, which is increasingly the
right choice for data whose shape varies between records.
Types map straight across
JSON already distinguishes numbers, booleans and null, so nothing has to be guessed. Numbers and booleans are
written unquoted, null becomes NULL, and strings are quoted and escaped.
Columns come from the keys
The column list is built from the object keys in the order they first appear across the array, so a field present
in only some records still gets a column — those rows simply write NULL for it. That means a partial
API response does not silently lose fields that appear later in the list.
Review before running
The generated CREATE TABLE infers types from a sample of your data. It is a useful first draft, but
it knows nothing about primary keys, foreign keys, indexes, or how large a value might get in future. Read it
before running it against anything real.
Common use cases
- Loading an API response into a database for analysis.
- Turning a JSON fixture into seed data for a migration.
- Moving records between two systems that speak different formats.
Frequently asked questions
How do I convert JSON to SQL?
Paste an array of objects into the left panel. The INSERT statements appear on the right, ready to copy or download as a .sql file.
How are nested objects handled?
By default they are expanded into dot-separated columns and arrays into indexed columns, so every value gets a column. Turn expansion off and each nested value is kept in a single column as compact JSON instead.
Which option suits a JSON or JSONB column?
Turn expansion off. The nested value is then written as one JSON string, which is exactly what a JSON or JSONB column expects to receive.
Are values escaped?
Yes. Apostrophes are doubled and, with MySQL quoting selected, backslashes and newlines are escaped too — so a value cannot terminate or extend the statement around it.
Can it infer the table definition?
Yes. Tick include CREATE TABLE and each column gets a type derived from the values present: integer, decimal, boolean or a VARCHAR sized to the longest value.
Should I run the output straight against a database?
Review it first. The types and table name are inferred from a sample of your data, so check them against the schema you actually want before running anything on real data.
Related tools
CSV to SQL Converter
This CSV to SQL converter turns spreadsheet rows into escaped INSERT statements.
SQL to JSON Converter
This SQL to JSON converter reads INSERT statements and gives you an array of typed records.
JSON to CSV Converter
This JSON to CSV converter turns an array of objects into spreadsheet-ready rows and columns.