JSON to SQL Converter

Turn a JSON array into SQL INSERT statements, with real types rather than guesses and nested objects flattened into columns.

Everything is generated in your browser. The escaping produces valid SQL literals for data you trust — never build runtime queries this way, use bound parameters.

What It Does

Paste a JSON array of records and get SQL that loads it. The advantage over converting from CSV is that JSON already carries its types, so nothing has to be inferred: a number is emitted unquoted because the document says it is a number, and a string of digits stays quoted because the document says it is a string. There is no guessing about whether 007 is a code, because JSON already answered that. Nested objects are flattened into underscore-joined columns since a table has no nesting, and arrays become JSON strings by default, which keeps them intact for a JSON column type. Records with different keys are handled — every key seen anywhere becomes a column and the gaps become NULL — and the tool tells you how many records were incomplete, because a lot of them usually means one table is the wrong shape.

When to Use It

  • An API response needs loading into a database table for analysis and you have the JSON already.
  • You are seeding a development database from a fixture file.
  • A data export arrived as JSON and your import tooling only speaks SQL.
  • You want to see what schema a JSON payload implies before designing the real table.
  • A one-off migration needs the statements in version control rather than run ad hoc from a script.

Worked Examples

[{"id":1,"name":"Widget","price":9.99,"active":true}]

Types come straight from the JSON — id is INTEGER, price DECIMAL, active BOOLEAN — with no inference involved. Converting the same data from CSV would require guessing all three.

[{"id":1,"address":{"city":"London","postcode":"SW1A"}}]

Nesting flattened. The address object becomes address_city and address_postcode, because a relational table has no nesting and the alternative is a second table you have not designed yet.

[{"id":1,"tags":["a","b"]},{"id":2}]

Two things at once. The array becomes a JSON string suitable for a JSON column, and the second record is missing tags entirely — so it gets NULL and the tool reports one incomplete record.

Features

Types taken from the JSON rather than inferred
Nested objects flattened into underscore-joined columns
Arrays kept as JSON strings or joined to a delimited value
Records with differing keys handled with NULL for the gaps
Optional CREATE TABLE with column types
MySQL backtick or standard double-quote identifiers
Adjustable rows per INSERT statement
Incomplete record count reported
Correct SQL literal escaping throughout
Runs entirely in your browser

How to Use

1. Paste a JSON array of objects, or a single object. 2. Set the table name. 3. Choose the dialect so identifiers are quoted correctly. 4. Decide how arrays should be stored and whether you want a CREATE TABLE. 5. Copy the SQL, then add the keys, indexes and constraints your schema actually needs.

Common Mistakes

  • Treating the escaping as injection protection. It produces valid literals for data you trust; runtime queries need bound parameters, which is a different mechanism entirely.
  • Shipping the generated CREATE TABLE. No primary key, no indexes, no constraints — those are design decisions a data sample cannot imply.
  • Ignoring a high count of incomplete records. It usually means the array contains more than one kind of record, and one table cannot represent that well however cleanly it converts.
  • Flattening deeply nested data into a table. Past two levels the column names become unwieldy, which is the data telling you it wants a relational structure.
  • Assuming a VARCHAR sized from your sample will hold future values. The longest string you happened to paste is not the longest that exists.

Frequently Asked Questions

Explore related topics

#JSON #SQL