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
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.
⚙ 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.⚙ Options, to set the table name and the database dialect.Copy result or Download file, then run it on your database.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.
[
{
"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"
]
}
}
]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');orders to the real table name, since it goes into both CREATE TABLE and INSERT.customer.name run.INSERT, tidy to paste into a query box. Turn it off for one statement per row when you may want to drop some.'450'. Change the column types or edit CREATE TABLE before you run it.a.0, a.1 columns. The limit is 200 columns.'', not NULL. If you need the difference, fix it with an UPDATE after loading.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.
No. Apostrophes are doubled. For MySQL, backslashes are escaped too.
Turn on Include DROP TABLE IF EXISTS in the SQL options, and Include CREATE TABLE if you also want the table definition.
It still works. Each key becomes a column. The flatten option only matters when the data holds child objects or arrays.