The complete guide

JSON to SQL: the complete guide

How types map, how identifiers and strings must be quoted, and how to run the result safely.

Try the JSON to SQL Converter

Why convert JSON to SQL?

JSON is the default format for everything that talks over HTTP. SQL is the default format for everything that stores relations. Almost every system you work with has to move data between the two — and the conversion is where data quietly gets corrupted.

The usual sources are:

  • API responses into a local database — for exploration, for a demo, or for a fixture file.
  • Webhook payloads into a queue table — so you can inspect what a partner actually sent.
  • Legacy exports into a new system — the old system exports JSON, the new system wants rows.
  • Third-party datasets — a vendor sends a JSON file, your warehouse wants a bulk load.

How do JSON types map to SQL types?

The mapping is mostly obvious, and mostly where imports break.

JSONSQL literalNotes
string'value'Always quoted; internal quotes doubled
number42Emitted unquoted so numeric columns accept it
true / falseTRUE / FALSEStandard SQL keywords
nullNULLNot the string 'null'
object'{...}'Serialised as JSON text
array'[...]'Serialised as JSON text
missing keyNULLWhen records have different keys

The single most common bug in hand-written SQL is rendering a JSON null as the quoted string 'null'. Your column then contains the four characters null instead of SQL NULL, and every WHERE x IS NULL query silently returns nothing.

How are identifiers quoted?

SQL identifiers — table names, column names, schema names — are quoted differently depending on the database:

  • PostgreSQL, SQLite, SQL Server, Oracle, ANSI SQL: double quotes, "users". This is the SQL standard and the default in HopConvert.
  • MySQL and MariaDB: backticks, `users`. MySQL also accepts double quotes by default, but only in ANSI_QUOTES mode — switching to MySQL quoting avoids ambiguity.
  • No quoting: also offered, for databases and migration tools that prefer bare identifiers.

Quoting matters for two reasons. First, reserved words — order, group, user, select — are common as column names, and an unquoted reserved word is a syntax error. Second, mixed-case identifiers are folded to lower case by some databases but not others, so quoting is what keeps your column names exactly as you defined them.

How are string literals escaped?

A string literal in SQL is wrapped in single quotes, and any single quote inside it is written twice:

'O''Brien'

That is the ANSI rule and it is what HopConvert emits for PostgreSQL and SQLite. MySQL additionally interprets backslash sequences inside string literals, so a literal backslash must be doubled and control characters must be escaped:

'C:\\path\\to\\file'
'line one\nline two'

HopConvert handles that automatically when the MySQL dialect is selected. Getting this wrong is the classic cause of "syntax error at or near" errors in the middle of an import.

How is the column list decided?

The converter reads every record and builds the column list from the union of all keys, in order of first appearance. Records that lack a key get NULL for that column. This matches the way you would write the CREATE TABLE statement yourself, and it is what makes a sparse JSON array importable without hand-editing.

Nested objects are flattened into column names joined by __ — {"user": {"name": "Alice"}} produces the column user__name. Match that to your schema, or rename the column in the database.

Should I use one INSERT per row or a multi-row INSERT?

Both are valid, and the difference is large in practice.

  • One INSERT per row: easy to read, easy to resume, and each statement is independent. But every statement is a round trip, so ten thousand rows means ten thousand round trips.
  • A single multi-row INSERT: one statement, one round trip, dramatically faster for bulk loads. Postgres, MySQL, SQLite, and SQL Server all accept it.

For a few dozen rows the difference is irrelevant. For a bulk load it is the difference between seconds and minutes. The multi-row form is the default in HopConvert for that reason.

Very large batches can also hit the maximum statement size in Postgres, so for really big payloads, generate chunks rather than one enormous statement.

Common edge cases

  • Top-level object instead of an array: treated as a single row.
  • Top-level array of scalars: converted to a single column named value.
  • Nested arrays and objects: serialised to JSON text and stored as a text column.
  • Missing keys: written as NULL.
  • Numbers beyond JavaScript's safe integer range: JSON.parse loses precision on integers above 2^53-1. For 64-bit IDs, keep them as strings in the source JSON.
  • Very long strings: fine, subject to your database's column limit.
  • Unicode and emoji: written as UTF-8.

Running the generated SQL safely

A few habits make a JSON-to-SQL import far less painful:

  1. Always wrap the whole thing in a transaction — BEGIN; before, COMMIT; after. If one row fails, nothing is half-applied.
  2. Test against a copy first. Run it on a snapshot, not production.
  3. Check the column list against your schema before running. The converter derives columns from the JSON, not from your table.
  4. Use ON CONFLICT DO NOTHING (or INSERT IGNORE) if re-running a backfill.
  5. Mind the transaction log. A million-row insert in one transaction can be heavy; chunk it.

And one more thing worth remembering: the generated SQL is generated from data you control, but it is still code. Read it before you run it against anything you care about.

FAQ

Frequently asked questions

Everything you need to know about converting JSON into SQL INSERT statements.

What is a JSON to SQL converter?
A JSON to SQL converter transforms a JSON array of records into SQL INSERT statements for Postgres, MySQL, SQLite, SQL Server, or DuckDB. It derives the column list from the keys in your JSON and formats every value as the correct SQL literal.
How do I convert JSON to SQL?
Open the JSON to SQL converter, paste your JSON array, then set your table name and schema in the settings cog. The generated INSERT statements appear immediately — copy them into your query editor or download them as a .sql file.
Is HopConvert free to use?
Yes — 100% free with no sign-up, no watermark, and no premium tier. Conversion runs entirely in your browser, so there are no running costs to pass on.
Is my JSON uploaded anywhere?
No. The SQL is generated locally in your browser. JSON payloads frequently contain personal data, internal identifiers, or credentials, and the converter has no backend that could receive them. The "Verify: nothing uploaded" button shows a live audit of every network request the page makes.
Which SQL dialects are supported?
PostgreSQL and ANSI SQL use double-quoted identifiers with standard literal escaping; MySQL and MariaDB use backtick identifiers with backslash escaping. Identifier quoting can also be turned off entirely.
How are nulls and booleans handled?
JSON null becomes SQL NULL, booleans become TRUE and FALSE, and numbers are written unquoted so numeric columns accept them. Hand-written SQL frequently gets this wrong, which is why the difference matters.
Should I use one INSERT per row or a multi-row INSERT?
A single multi-row INSERT is much faster for bulk loads because it is one round trip instead of thousands. HopConvert defaults to that, but you can switch to one statement per row in settings if your migration tool prefers it.
What about nested objects in the JSON?
Nested objects are flattened into column names joined by __, so {"user": {"name": "Alice"}} becomes the column user__name. Nested arrays and objects are serialised as JSON text in a single column.

Try the JSON to SQL converter

Free, instant, and private — your JSON never leaves this tab.

Open the JSON to SQL Converter

More free tools: JSON to CSV · CSV to JSON · XML to CSV · JSON to YAML · YAML to JSON · JSONL to CSV · JSON to SQL · JSON to Markdown · JSON to Excel