1xA2ZOne Data. Any Format.
Live syncLocal-first · no data upload

Convert JSON to SQL

The tool only handles tabular data. Turn flattening on in the JSON tab, paste a JSON array of objects into the Quick paste box and get CREATE TABLE plus INSERT on the SQL tab. Nested objects become a.b.c columns and arrays become a.0, a.1.

Runs entirely in your browser. Your data is never uploaded. Tiếng Việt

01

Spreadsheet

SheetsExcelCSVTSV
✦ Quick pasteSheets / Excel, CSV, TSV, Markdown, JSON, HTML, LaTeX, wiki…
0 rows · 0 columnsSelected cell: A1
02

Live Output

Markdowntwo-way
SyncedEdit directly; the table on the left updates itself
0 characters
Every change is processed right in your browserReady · LocalUTF-8 · by xuanhieu.org

When you need to convert JSON to SQL

You want SQL from JSON when you need to load API data into a database to try queries. JSON is rarely flat, while a SQL table has fixed columns. That is why this page's sample reads nested JSON with the flatten option before it writes statements. Treat the result as a starting point to adjust, not a finished schema.

How to do it

  1. Open the JSON tab, go to ⚙ Options and tick Flatten nested objects (a.b.c), then paste your JSON array into Quick paste and press Load into table ↵ (or use Import file with a .json file). With flattening off, nested parts stay in the cell as JSON text.
  2. Check the grid: every nested key is a column. Rows with fewer array items get empty cells.
  3. Open the SQL tab, then ⚙ Options, to set the table name and the database dialect.
  4. Press Copy result or Download file, then run it on your database.

A real example

Columns such as customer.name and order.items.0 are named after the key path and quoted with double quotes. Order A2 has one item, so order.items.1 and order.items.2 are ''. The total 450 is also inside single quotes.

Input · JSON

[
  {
    "id": "A1",
    "customer": {
      "name": "Anna Reed",
      "city": "London"
    },
    "order": {
      "total": 450,
      "items": [
        "book",
        "pen"
      ]
    }
  },
  {
    "id": "A2",
    "customer": {
      "name": "Ben Cole",
      "city": "Leeds"
    },
    "order": {
      "total": 1250,
      "items": [
        "backpack"
      ]
    }
  },
  {
    "id": "A3",
    "customer": {
      "name": "Cara Lin",
      "city": "Bristol"
    },
    "order": {
      "total": 299.5,
      "items": [
        "notebook",
        "pen",
        "ruler"
      ]
    }
  }
]

Result · SQL

CREATE TABLE "orders" (
  "id" TEXT,
  "customer.name" TEXT,
  "customer.city" TEXT,
  "order.total" TEXT,
  "order.items.0" TEXT,
  "order.items.1" TEXT,
  "order.items.2" TEXT
);
INSERT INTO "orders" ("id", "customer.name", "customer.city", "order.total", "order.items.0", "order.items.1", "order.items.2") VALUES
  ('A1', 'Anna Reed', 'London', '450', 'book', 'pen', ''),
  ('A2', 'Ben Cole', 'Leeds', '1250', 'backpack', '', ''),
  ('A3', 'Cara Lin', 'Bristol', '299.5', 'notebook', 'pen', 'ruler');

Options worth changing

Flatten nested objects (a.b.c)
Needed for JSON with child objects. Turned off, a whole child object sits in one cell as JSON text, and the SQL contains that string.
Table name
Change orders to the real table name, since it goes into both CREATE TABLE and INSERT.
Database
Standard, PostgreSQL / SQLite, MySQL / MariaDB and SQL Server quote column names differently. Pick yours so dotted columns like customer.name run.
Batch INSERT
Turn it on for one multi-row INSERT, tidy to paste into a query box. Turn it off for one statement per row when you may want to drop some.

Common problems

Limits

Frequently asked questions

Why are numbers inside single quotes?

Every value is a string and columns are declared TEXT, so numbers are written as strings. Change the column type afterwards if you need it.

Will apostrophes in my data break the statement?

No. Apostrophes are doubled. For MySQL, backslashes are escaped too.

How do I get DROP TABLE IF EXISTS?

Turn on Include DROP TABLE IF EXISTS in the SQL options, and Include CREATE TABLE if you also want the table definition.

What if my JSON has no nested objects?

It still works. Each key becomes a column. The flatten option only matters when the data holds child objects or arrays.

Related conversions

1xA2Z · Guide

Table statistics