SmartQueryTools

Convert JSON to SQL Online

Convert JSON files to SQL INSERT statements directly in your browser. Copy or download the generated SQL — no upload required.

About converting JSON to SQL

JSON to SQL turns an API response or document export into a script you can run against a relational database: a CREATE TABLE statement followed by one INSERT per record. It is handy for seeding a local PostgreSQL or SQLite database from a JSON fixture, reproducing a bug with production-shaped data, or moving a small MongoDB collection into a table without writing a loader.

The table is named after your file, so issues.json produces a table called "issues". Column types come from the JSON values: whole numbers map to BIGINT, decimals to DOUBLE PRECISION, true and false to BOOLEAN, plain dates to DATE, and strings to TEXT. Review them before running the script. DOUBLE PRECISION is a binary float in every database, so change money columns to DECIMAL.

Identifiers are wrapped in double quotes, which PostgreSQL, SQLite and standard SQL accept. MySQL and MariaDB treat double quotes as string delimiters unless ANSI_QUOTES mode is enabled for the session, or you swap them for backticks. The script covers the first 1,000 records only. Nested objects and arrays go into TEXT columns as JSON strings. Cast them to json or jsonb in PostgreSQL if you want to query inside them.

Worked example

A small sample file, converted with the default settings.

Input (JSON)

[
  {
    "id": 4101,
    "title": "Login fails on Safari 17",
    "state": "open",
    "comments": 3,
    "created": "2026-03-02",
    "assignee": "maria"
  },
  {
    "id": 4102,
    "title": "Export slow, then times out",
    "state": "closed",
    "comments": 8,
    "created": "2026-03-03",
    "assignee": null
  },
  {
    "id": 4103,
    "title": "Add dark mode",
    "state": "open",
    "comments": 12,
    "created": "2026-03-05",
    "assignee": "dev-team"
  },
  {
    "id": 4104,
    "title": "Crash on empty file",
    "state": "closed",
    "comments": 0,
    "created": "2026-03-06",
    "assignee": "li.wei"
  }
]

Output (SQL)

CREATE TABLE IF NOT EXISTS "data" (
  "id" BIGINT,
  "title" TEXT,
  "state" TEXT,
  "comments" BIGINT,
  "created" DATE,
  "assignee" TEXT
);

INSERT INTO "data" VALUES (4101, 'Login fails on Safari 17', 'open', 3, '2026-03-02', 'maria');
INSERT INTO "data" VALUES (4102, 'Export slow, then times out', 'closed', 8, '2026-03-03', NULL);
INSERT INTO "data" VALUES (4103, 'Add dark mode', 'open', 12, '2026-03-05', 'dev-team');
INSERT INTO "data" VALUES (4104, 'Crash on empty file', 'closed', 0, '2026-03-06', 'li.wei');

What changes when you convert JSON to SQL

  • The script opens with CREATE TABLE IF NOT EXISTS, listing each JSON key as a column.
  • id and comments become BIGINT, title, state and assignee become TEXT, and created becomes DATE.
  • Strings are single-quoted, with any apostrophe inside a value doubled.
  • null becomes the SQL keyword NULL, as in the INSERT for issue 4102.
  • Booleans are written as lowercase true and false. Integers above 9,007,199,254,740,991 are quoted, and most databases cast them to BIGINT on insert.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Frequently Asked Questions

Why does the script stop after 1,000 records?

The SQL output is built as text in your browser and is meant for fixtures and small imports. One INSERT per row is also slow for bulk loads. For larger JSON files, convert to CSV and use COPY in PostgreSQL, LOAD DATA in MySQL or .import in SQLite.

Will the script run on SQL Server?

Mostly, with edits. SQL Server accepts double-quoted identifiers by default, but it has no BOOLEAN type (use BIT), TEXT is deprecated (use NVARCHAR(MAX)), and CREATE TABLE IF NOT EXISTS is not supported. Replace those parts before running it.

How are nested JSON fields handled?

Each object or array is written as a JSON string in a TEXT column, such as '{"city":"Leeds"}'. PostgreSQL can cast that to jsonb and MySQL to JSON. If you would rather have one scalar per column, flatten the JSON first.

What is SQL format?

SQL (Structured Query Language) is the standard language for querying and manipulating relational databases. The output contains CREATE TABLE and INSERT INTO statements ready to run against any SQL-compatible database.

Related Tools