{}JSONLint.app

JSON to SQL Converter

Convert JSON arrays to SQL CREATE TABLE and INSERT statements. Paste your JSON:

Loading...
Loading...

Convert JSON to SQL

This tool transforms JSON data into SQL statements for database import. It generates CREATE TABLE statements with inferred column types and INSERT statements with properly escaped values.

Supported Databases

DatabaseIdentifier QuotesJSON Support
PostgreSQL"column"JSONB type
MySQL`column`JSON type
SQLite"column"TEXT (store as string)
SQL Server[column]NVARCHAR (store as string)

Type Mapping

The converter infers SQL types from JSON values:

JSON TypePostgreSQLMySQL
stringVARCHAR / TEXTVARCHAR / TEXT
integerINT / BIGINTINT / BIGINT
decimalDOUBLEDOUBLE
booleanBOOLEANTINYINT(1)
nullTEXT NULLVARCHAR NULL
date stringDATEDATE
datetime stringTIMESTAMPDATETIME
object/arrayJSONBJSON

Example Output

From this JSON:

[
  {"id": 1, "name": "Alice", "active": true},
  {"id": 2, "name": "Bob", "active": false}
]

PostgreSQL output:

CREATE TABLE "users" (
  "id" INT NOT NULL,
  "name" VARCHAR(50) NOT NULL,
  "active" BOOLEAN NOT NULL
);

INSERT INTO "users" ("id", "name", "active")
VALUES
  (1, 'Alice', TRUE),
  (2, 'Bob', FALSE);

Options Explained

Table name

The name used for the CREATE TABLE and INSERT statements. Automatically quoted with the appropriate syntax for your database.

Output type

  • CREATE + INSERT — Full table creation with data
  • CREATE TABLE only — Schema definition only
  • INSERT only — Data insertion only (for existing tables)

Include NULLs

When enabled, null values are inserted as NULL. When disabled, they use DEFAULT (requires column defaults defined).

Handling Special Cases

Nested objects

Nested JSON objects and arrays are stored as JSON/JSONB columns in PostgreSQL and MySQL, or as TEXT strings in SQLite and SQL Server.

String escaping

Single quotes in strings are automatically escaped by doubling them (''). This prevents SQL injection in the generated statements.

Large datasets

Insert statements are batched (default 100 rows per statement) for better performance and to avoid query size limits.

Common Use Cases

  • Database seeding — Initialize test/dev databases
  • Data migration — Move data from NoSQL to SQL
  • API data import — Import JSON API responses
  • Schema generation — Create tables from JSON structure

Related Tools

Frequently Asked Questions

Is the output safe from SQL injection?

The generated SQL properly escapes string values. However, always review generated SQL before running on production databases, and prefer parameterized queries in application code.

Can I convert a single JSON object?

Yes. Single objects are automatically wrapped in an array to generate a single-row insert.

How are column types determined?

Types are inferred from the first row of data. If your data has varying types, you may need to adjust the generated schema manually.

What about primary keys and indexes?

The generator creates basic column definitions. Add PRIMARY KEY, UNIQUE, INDEX, and other constraints manually based on your requirements.

Common Mistakes & Pro Tips

  • Column types are inferred from sampled values and can guess wrongThe converter looks at the JSON values to pick a SQL type — integers become INT, decimals become a FLOAT/DECIMAL, true/false become BOOLEAN, and everything else falls back to VARCHAR or TEXT. If only the first few rows are sampled, a column that is mostly integers but occasionally has a string will be typed as INT and fail on insert. Review the generated CREATE TABLE and widen types where your data is mixed.
  • Single quotes in values must be escaped or the SQL breaksA string like O'Brien must be written as 'O''Brien' (doubling the quote) inside a SQL string literal; otherwise the statement is syntactically broken and, with untrusted input, becomes an injection vector. A correct converter doubles every embedded single quote. Never paste generated INSERTs from untrusted JSON into a production database without reviewing the escaping.
  • NULL is a keyword, not the string 'NULL'A JSON null should become the bare SQL keyword NULL (unquoted), while the four-character string "NULL" should become 'NULL' (quoted). Mixing these up either stores the literal text NULL or nulls out a column you meant to populate. Check that your converter distinguishes the JSON null type from a string that happens to read NULL.
  • Nested objects and arrays have no flat column to live inRelational columns are scalar, so a nested object or array can't map to a single typed column directly. Converters usually serialize the nested value as a JSON string and put it in a TEXT/JSON column, or skip it. If you need true relations, split the nested array into a child table with a foreign key rather than inlining it.
  • Identifiers and dialects vary — VARCHAR length and AUTO_INCREMENT aren't universalGenerated DDL targets a specific dialect: MySQL uses AUTO_INCREMENT and backtick quoting, PostgreSQL uses SERIAL/IDENTITY and double-quoted identifiers, and SQLite is loosely typed. A VARCHAR(255) guess may be too short for long text, and reserved words used as column names need quoting. Confirm the output matches your target database before running it.

Frequently Asked Questions

How do I generate SQL INSERT statements from a JSON array?

Supply a JSON array of objects and the tool derives a column list from the union of keys, optionally emits a CREATE TABLE with inferred types, and produces one INSERT statement per object. Values are quoted and escaped according to SQL rules, with JSON null mapped to the NULL keyword. You can then copy the script and run it against your database.

How does the converter decide each column's SQL data type?

It inspects the JSON values and infers a type: whole numbers map to INTEGER, numbers with decimals to a floating or DECIMAL type, true/false to BOOLEAN, and strings (or mixed values) to VARCHAR or TEXT. Because inference is based on the values present, a column with inconsistent types defaults to a string type to stay safe. Always review the generated CREATE TABLE and adjust lengths or types for your schema.

Are quotes and special characters escaped to prevent broken or injectable SQL?

Yes, embedded single quotes are doubled (O'Brien becomes 'O''Brien') so each string literal is syntactically valid. This also neutralizes the most common SQL-injection break-out. Even so, generated statements from untrusted input should be reviewed, since safe escaping is not a substitute for parameterized queries in application code.

What table and column names are used?

The column names come directly from the JSON object keys, and the table name is typically a default like data or one you specify in the tool. If a key is a SQL reserved word or contains spaces, it should be quoted using the target dialect's identifier syntax (backticks in MySQL, double quotes in PostgreSQL). Rename keys beforehand if you want cleaner column names.

How are nested objects or arrays inside each record handled?

Since SQL columns hold scalar values, nested structures are usually serialized into a single column as a JSON string (suited to a TEXT or native JSON column) rather than expanded. They are not automatically broken into related tables. For a normalized schema, extract nested arrays into their own table with a foreign key referencing the parent row.

Can I target MySQL, PostgreSQL, or SQLite specifically?

Dialects differ in identifier quoting, auto-increment syntax, and type names, so the generated DDL should match your database — MySQL uses backticks and AUTO_INCREMENT, PostgreSQL uses double quotes and SERIAL or IDENTITY, and SQLite is flexibly typed. Pick the matching dialect if the tool offers one, or adjust the keywords after generation. Running PostgreSQL-style DDL on MySQL (or vice versa) will otherwise error.

Does my JSON leave the browser when generating SQL?

No, the parsing, type inference, and statement generation all run client-side, so your data and the resulting SQL never touch a server. This matters because database seed data is often sensitive. The output is created and stays on your machine until you copy or save it.