How to Convert JSON to SQL
To convert JSON to SQL, paste an array of objects into a converter and name the target table. Each object becomes a row and each key becomes a column. Quote every identifier so reserved words such as order do not break the statement, and read the output before running it — generated SQL escapes values but does not parameterise them.
JSON to SQL Converter
Turn a JSON array into INSERT statements.
This is a common job when seeding a development database, loading a small reference table, or moving a handful of records between systems. The conversion itself is mechanical; almost all the difficulty is in three details that produce SQL which looks right and is not.
Those are: reserved words used as field names, records that do not all carry the same fields, and nested values that have no column type. Each has a correct answer, and getting any of them wrong fails loudly at best and corrupts data quietly at worst.
Step by step
-
Start from an array of objects
Each object becomes one row and its keys become columns. A bare object is treated as a single row; an array of arrays has no field names and cannot be converted.
-
Name the table and pick the quoting style
MySQL and MariaDB use `backticks`, PostgreSQL and standard SQL use "double quotes", SQL Server uses [brackets]. Using the wrong style is a syntax error, not a stylistic difference.
-
Let every identifier be quoted
order, group, key, user and desc are all reserved words and all common field names. Quoting only the identifiers that look unusual leaves those bare and the statement fails. Quoting everything is never wrong.
-
Check the column list
When records carry different fields, the column list should be the union of all of them, with NULL filling the gaps. If your converter uses only the first record's keys, later records silently lose data.
-
Decide what to do with nested values
An object or array has no column type. Storing it as JSON text is the honest default; if you need the values as columns, flatten the document before converting.
-
Read the SQL before running it
Generated SQL escapes quotes but is not parameterised. Treat it as a script to review, run it against a development database first, and never paste untrusted data through it into production.
Example
Note the quoted "order" — a reserved word — and the NULL filling the field the first record lacks.
JSON
[
{ "id": 1, "order": 10 },
{ "id": 2, "order": 20, "note": "late" }
]
SQL
INSERT INTO "orders" ("id", "order", "note") VALUES
(1, 10, NULL),
(2, 20, 'late');
Frequently asked questions
Why must identifiers be quoted?
What if my records have different fields?
Is generated SQL safe to run?
Why is there no CREATE TABLE?
How do I handle dates?
Tools used in this guide
All tools →- JSON to SQL Converter Turn a JSON array into INSERT statements. In your browser
- JSON Flatten Turn nested JSON into a flat map of dot-separated paths. In your browser
- JSON Formatter Beautify, validate and sort JSON with precise error messages. In your browser
- SQL Formatter Reformat dense SQL into readable, indented statements. In your browser
- CSV to JSON Converter Turn CSV rows into a clean JSON array of objects. In your browser
Related guides
All guides →Last reviewed .