JSON to SQL Converter

Generate SQL for SQLite, MySQL, or PostgreSQL from valid JSON. Set a table name, choose whether to include CREATE TABLE and INSERT statements, and review the inferred columns before copying or downloading the SQL.

Input JSON

0 characters

SQL output

Your SQL output will appear here.

Paste JSON or open a file to begin.

SQL mapping and safety

Arrays of objects are converted to rows, and a single object becomes one row. With flattening enabled, nested objects become dot-path columns; arrays and unflattened objects are stored as JSON text. SQL identifiers are quoted for the selected dialect and string literals escape single quotes. Review inferred column types and generated statements before running them in a database. This tool generates SQL text only; it does not connect to a database.

Convert JSON to SQL Statements

When an API or application gives you records as JSON but a database needs rows, a converter can draft the table definition and insert statements. This JSON to SQL converter supports SQLite, MySQL, and PostgreSQL. It infers columns and types from the input, lets you choose a table name, and can generate a CREATE TABLE statement, an INSERT statement, or both.

Paste valid JSON or open a JSON file, select the database dialect, and review the generated SQL before using it. The conversion runs in your browser; this tool creates SQL text but does not connect to or change a database.

How to Convert JSON to SQL

  1. Paste JSON into the input area, choose Open JSON, or load the sample.
  2. Select SQLite, MySQL, or PostgreSQL to match the database where the SQL will run.
  3. Enter a table name using letters, numbers, or underscores. It must begin with a letter or underscore.
  4. Choose whether to include the table definition, insert data, and flatten nested objects. At least one SQL statement option must be selected.
  5. Select Generate SQL. Check the SQL, row and column counts, and inferred types before copying or downloading the output.

If the input is rejected as invalid JSON, check its syntax with the JSON Validator and try again.

Example: JSON Records to PostgreSQL

This example uses an array of customers, the PostgreSQL dialect, the table name customers, and both statement options. With flattening enabled, profile.city becomes a column. The array in tags stays JSON text in a text column.

Input JSON

[
  {"id": 101, "name": "Mina Patel", "active": true, "profile": {"city": "Pune"}, "tags": ["beta", "email"]},
  {"id": 102, "name": "O'Neil", "active": false, "profile": {"city": "Austin"}, "tags": ["new"]}
]

Generated SQL

CREATE TABLE "customers" (
  "id" INTEGER,
  "name" TEXT,
  "active" BOOLEAN,
  "profile.city" TEXT,
  "tags" TEXT
);

INSERT INTO "customers" ("id", "name", "active", "profile.city", "tags")
VALUES
  (101, 'Mina Patel', TRUE, 'Pune', '["beta","email"]'),
  (102, 'O''Neil', FALSE, 'Austin', '["new"]');

The generated values match the selected PostgreSQL dialect. The apostrophe in O'Neil is doubled inside the SQL string literal. Select another dialect to generate its corresponding identifier quotes, boolean values, and column types.

Supported SQL Dialects and Inferred Types

The converter chooses a type from the values observed in each column. Common mappings include:

JSON valuesSQLiteMySQLPostgreSQL
Whole numbersINTEGERINTEGERINTEGER
Decimal numbersREALDOUBLEDOUBLE PRECISION
BooleansINTEGER (1 or 0)TINYINT(1)BOOLEAN
Strings and nested valuesTEXTTEXTTEXT

When a column mixes strings with numbers, or mixes booleans with another type, it is treated as text so the different values can be represented. Whole numbers and decimals together use the dialect’s decimal-number type. Nulls and missing fields are emitted as NULL; they do not determine a column type. If a column contains only nulls, its inferred type is text.

How JSON Structure Maps to SQL Columns

Arrays of objects

An array of objects is the clearest input for a relational table: each object becomes a row and property names across the records become columns. A property missing from a particular object is inserted as NULL. One INSERT statement contains all input rows, rather than separate inserts for each record.

Single objects and primitive values

A single object becomes one row. A top-level primitive, or each primitive in a top-level array, is placed in a column named value. An array of arrays is treated as values in that column; it is not automatically expanded into several SQL columns.

Nested objects and arrays

With Flatten nested objects enabled, nested objects are expanded into dotted column names such as profile.city. Turn flattening off to keep each nested object as JSON text in one column. Arrays inside records are also stored as JSON text; the converter does not expand array items into rows or create related tables.

If an API response wraps a list under a key such as data or results, this tool treats the wrapper as a record and stores the array in that field as JSON text. It does not automatically unwrap the inner array. Extract the list of records first if you want each item to become a database row.

Review the SQL Before Running It

Identifiers are quoted for the selected dialect, and single quotes inside string values are escaped. Those safeguards help create well-formed output, but inferred SQL is still a starting point: review it for your schema, database rules, and data requirements before execution.

Frequently Asked Questions

Which SQL databases does the converter support?

It generates SQL for SQLite, MySQL, and PostgreSQL. Choose the dialect that matches your destination database before generating the statements.

Can I generate only INSERT statements?

Yes. Turn off Include CREATE TABLE and leave Include INSERT statements on. You can also generate only a table definition, or include both. At least one option must remain selected.

How are nested JSON objects converted?

By default, nested objects are flattened into dotted column names such as profile.city. Turn off flattening to store each object as JSON text in a column. Nested arrays remain JSON text either way.

What happens to null or missing properties?

They become SQL NULL. If a field is missing from one object but present in others, the column is still included and the missing row receives NULL.

Does the tool connect to my database?

No. It generates SQL text in your browser for you to review, copy, or download. You choose where and whether to run it.

Is the generated SQL ready to run without changes?

It is a useful starting point, but review the inferred types, table name, null behavior, large numeric values, and database-specific requirements first. The converter does not know your existing schema or constraints.

Related JSON Tools

Use the JSON Validator to check input syntax, the JSON Formatter to make records easier to inspect, or the JSON to CSV Converter and JSON to Excel Converter when you need spreadsheet output.