JSON to SQL Converter

Turn a JSON array of objects into INSERT statements and a CREATE TABLE, keeping nested objects as JSON or flattening them into columns.

0 characters

Or drop a .json/.jsonl/.txt file onto the box above.

Database
Statements
Values
Columns

How to use

  1. Paste a JSON array of objects, drop a .json or .jsonl file on the box, or press Load sample.
  2. Pick your database under Dialect and type the Table name.
  3. Choose how Nested objects are stored: kept as JSON text, or flattened into columns.
  4. Set Rows per INSERT, and untick Add CREATE TABLE if the table already exists.
  5. Copy to clipboard or Download .sql, or open the result in the SQL Formatter with Format this SQL.

How JSON values become SQL columns

Each object becomes a row and each key a column. The columns are every key that appears in any object, in the order they first appear, so objects with missing keys or keys in a different order still line up: a missing key is NULL. Because JSON already says what each value is, the column types follow it: numbers become INTEGER, BIGINT or a DECIMAL sized to the data (a number written with an exponent gets a floating-point type), true and false become a boolean, and strings stay text unless every one of them is a real date or timestamp.

Numbers are copied exactly as they appear in the JSON rather than through JavaScript's number type, so long IDs keep every digit. Nested objects and arrays are written as compact JSON into a JSON column (JSON in MySQL, JSONB in PostgreSQL, NVARCHAR(MAX) in SQL Server, TEXT in SQLite), or, with Flatten into columns, each nested key gets a column of its own named parent_child.

Strings are escaped the way the chosen database reads them, with the same rules as the CSV to SQL Converter: a doubled single quote everywhere, doubled backslashes for MySQL (which matters here, because JSON text inside a JSON column is full of backslashes) and N'…' for SQL Server.

Example

The array that Load sample inserts, with a null, an apostrophe, a nested object and an array:

[
  {
    "id": 1,
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "active": true,
    "signup": "2026-01-15",
    "address": { "city": "London", "zip": "01234" },
    "tags": ["admin", "beta"]
  },
  {
    "id": 2,
    "name": "Seán O'Brien",
    "email": null,
    "active": false,
    "signup": "2026-02-03",
    "address": { "city": "Dublin", "zip": null },
    "tags": []
  }
]

becomes, with the default options (Standard SQL, nested objects kept as JSON text):

CREATE TABLE my_table (
  id INTEGER,
  name VARCHAR(12),
  email VARCHAR(15),
  active BOOLEAN,
  signup DATE,
  address VARCHAR(31),
  tags VARCHAR(16)
);

INSERT INTO my_table (id, name, email, active, signup, address, tags) VALUES
  (1, 'Ada Lovelace', 'ada@example.com', TRUE, '2026-01-15', '{"city":"London","zip":"01234"}', '["admin","beta"]'),
  (2, 'Seán O''Brien', NULL, FALSE, '2026-02-03', '{"city":"Dublin","zip":null}', '[]');

With PostgreSQL the two nested columns are address JSONB, tags JSONB. With Flatten into columns as well, the table starts like this, and tags stays JSON because it is an array:

CREATE TABLE my_table (
  id INTEGER,
  name TEXT,
  email TEXT,
  active BOOLEAN,
  signup DATE,
  address_city TEXT,
  address_zip TEXT,
  tags JSONB
);

Options explained

Edge cases and common errors

INSERT INTO my_table (a, b) VALUES
  (1, NULL),
  (3, 2);

Do the same thing in code

import json, sqlite3
import pandas as pd

rows = json.load(open("data.json", encoding="utf-8"))
df = pd.json_normalize(rows, sep="_")  # nested keys become address_city
df = df.map(lambda v: json.dumps(v) if isinstance(v, list) else v)
df.to_sql("my_table", sqlite3.connect("data.db"), index=False)
INSERT INTO my_table
SELECT * FROM jsonb_populate_recordset(NULL::my_table, '[{"id": 1, "name": "Ada"}]');

pandas' json_normalize flattens nested objects much like Flatten into columns; lists have to be turned into JSON text first, which is the second line. PostgreSQL can also read the JSON itself: jsonb_populate_recordset maps each object onto an existing table's columns by name. If the data is going to a spreadsheet instead of a database, use the JSON to CSV Converter, and the SQL Formatter lays out the generated script before you run it.

JSON to SQL Converter FAQ

What JSON shapes does it accept?

An array of objects, one row per object, is the usual case. It also takes a single object (one row), an API response that wraps the rows in a property such as data or results (the rows are taken from that array, and a note says which), an array of arrays (columns column_1, column_2 …) and JSON Lines, one object per line, as log exports write it.

Why is a number in quotes, like “42”, written as text?

Because the JSON says it is a string. Whoever produced it quoted the value on purpose, which is common for IDs, codes and phone numbers that must keep leading zeros. The tool follows the JSON types: {"code": "42", "note": "", "email": null} becomes ('42', '', NULL), with the empty string and the null kept apart.

Should nested objects be JSON columns or flattened?

Flatten them when you will filter, join or index on the nested fields, and when every row has the same nested keys. Keep them as JSON when the shape differs from row to row or you only need to store and return it. PostgreSQL and MySQL can still query inside a JSON column. Arrays are always stored as JSON, because a list has no fixed set of columns.

Are large numbers kept exactly?

Yes. JavaScript's own JSON reader turns 9007199254740993 into 9007199254740992, because its numbers have 53 bits of precision. This tool keeps every number exactly as it is written in the JSON, so that ID is inserted as (9007199254740993). The same goes for decimals: 1.50 stays 1.50, and the DECIMAL column gets enough digits to hold it.

Is my data uploaded anywhere?

No. The conversion runs in your browser with JavaScript, there is no server side that could receive the JSON, and nothing is stored. You can load the page, disconnect from the network and convert an export full of customer records. Your browser remembers the options you picked; the JSON itself is not kept.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta.