Report

Help us improve this tool

JSON to SQL Converter

Convert a JSON array into SQL INSERT statements with an optional CREATE TABLE statement. Choose MySQL, PostgreSQL, or SQLite dialect, set the table name, and batch large datasets.

O M T

Why Convert JSON to SQL?

JSON is the default format for API responses, exports, and log snapshots, while relational databases still run most production data. Moving a JSON array into a database usually means writing INSERT statements by hand, and that gets tedious fast: quoting rules differ per database, strings need escaping, and one wrong delimiter can silently corrupt a value.

This converter takes a JSON array of objects and produces ready to run SQL. Each object becomes one row, each key becomes a column, and the output is correct for the database you target, including identifier quoting, string escaping, and boolean representation.

Supported Dialects

The tool generates SQL for three of the most common databases, with the differences that actually matter handled automatically:

  • MySQL: identifiers are wrapped in backticks, backslashes are escaped inside strings, booleans become TRUE or FALSE, and inferred types use INT, DOUBLE, and TINYINT(1).
  • PostgreSQL: identifiers use double quotes, string escaping follows standard_conforming_strings behavior, booleans become TRUE or FALSE, and inferred types use INTEGER, DOUBLE PRECISION, and BOOLEAN.
  • SQLite: identifiers use double quotes, booleans become 0 or 1, and inferred types use INTEGER and REAL.

Single quotes inside strings are doubled in every dialect, which is the standard way to escape them.

The Expected JSON Shape

The input must be an array of objects, for example a list of products, users, or events. Two rules keep the output predictable:

  • Columns are the union of all keys. If one object has an extra field, the column is added, and rows that lack it insert NULL in that position.
  • Nested objects and arrays become JSON text. A value like an address object is inserted as its JSON string, which preserves the data in a TEXT column without flattening or losing information.

Missing values written as JSON null insert SQL NULL. Numbers are written as numeric literals, so they land in numeric columns without casting strings.

The CREATE TABLE Option

With Include CREATE TABLE enabled, the first statement creates the table before inserting anything. Column types are inferred by scanning every row:

  • All whole numbers become an integer type, and any decimal value promotes the column to a floating point type.
  • Columns containing only true or false use the dialect's boolean representation.
  • Everything else, including text, dates stored as strings, and nested JSON, lands in a TEXT column.
  • Columns that are entirely null fall back to TEXT.

Treat the generated table as a starting point. Add primary keys, indexes, defaults, and tighter column types that reflect your actual schema, then run the inserts.

Batching Large Datasets

Rows per INSERT controls how many rows go into each INSERT statement. Databases limit how much a single statement can contain: MySQL has max_allowed_packet, PostgreSQL caps bind parameters, and SQLite has an expression depth limit. Batching 100 rows per statement is a safe default that also parses faster than one statement per row. For very large exports, reduce the batch size or split the JSON into chunks first.

How to Use the Converter

  1. Paste or upload your JSON array in the left panel. The built-in sample shows nested objects and a null value.
  2. Pick the SQL dialect, set the table name, and choose how many rows each INSERT should carry.
  3. The SQL output appears immediately, starting with CREATE TABLE when that option is enabled.
  4. Copy the statements or download them as a .sql file and run them against your database.

Escaping and Safety Notes

Values are escaped so that quotes inside strings cannot break the statement, which also blocks the classic quote based injection route for the data you paste. Identifier quoting protects column names that collide with reserved words. Even so, review generated SQL before running it against a production database, and wrap large inserts in a transaction so a failure does not leave a half loaded table.

Privacy

Conversion runs entirely in your browser. Export files frequently contain business data, user records, or configuration, and none of it is uploaded, stored, or logged. The tool also works offline after the page loads.

Frequently Asked Questions

What JSON format does the converter expect?

A JSON array where every element is an object with at least one key. Each object becomes one row and keys become columns. A single object, an array of arrays, or an array containing numbers and strings is rejected with a message pointing at the offending row.

How are missing keys and null values handled?

Columns are collected from every object in the array. When a row does not contain a key, NULL is inserted for that column. JSON null values are also inserted as SQL NULL, so the two behave the same in the database.

Can I convert a single JSON object instead of an array?

Wrap the object in square brackets to make it a one element array. That produces a single row INSERT and, if enabled, a CREATE TABLE for the columns the object defines.

How are nested objects and arrays inserted?

They are serialized with JSON.stringify and inserted as a quoted string, so a nested address or list of tags is preserved exactly as JSON text in a TEXT column. Flatten the data first if you need separate columns for nested fields.

Why is my table name rejected?

Identifiers must start with a letter or underscore and contain only letters, numbers, and underscores after that. This keeps the generated statement valid and avoids quoting problems with spaces or punctuation. Rename the table in your database conventions if needed.

Is my data uploaded to a server?

No. Parsing, escaping, and statement generation all run locally in your browser. Nothing is transmitted, stored, or logged, and the tool keeps working without a connection once loaded.

Related Tools

Continue your database workflow with these tools: