Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

JSON to SQL converter

This JSON to SQL converter turns an array of objects into a table definition and one INSERT per object. The sample of 3 orders has 7 distinct keys, so it becomes a CREATE TABLE with 7 columns and 3 INSERT statements, with the surname O'Brien escaped and a missing note written as NULL.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Use schema.table to write both parts.
Database
Rows per INSERT
Options
SQL for orders

3 rows7 columns, 3 INSERT statements, 629 bytes

CREATE TABLE "orders" ( "id" BIGINT, "customer" VARCHAR(12), "paid" BOOLEAN, "total" DECIMAL(5, 2), "placed" DATE, "tags" JSONB, "note" VARCHAR(7) ); INSERT INTO "orders" ("id", "customer", "paid", "total", "placed", "tags", "note") VALUES (1, 'Ada Lovelace', true, 129.5, '2026-03-14', '["gift","express"]', NULL); INSERT INTO "orders" ("id", "customer", "paid", "total", "placed", "tags", "note") VALUES (2, 'O''Brien', false, 80, '2026-03-15', NULL, 'C:\temp'); INSERT INTO "orders" ("id", "customer", "paid", "total", "placed", "tags", "note") VALUES (3, 'Zoë Müller', NULL, 0.25, '2026-03-16', NULL, NULL);
  • PostgreSQL
  • CREATE TABLE included
  • One INSERT per row
  • 4 values were missing from some objects and are written as NULL.
  • 1 column holds nested objects or arrays, stored as JSON text.
Columns and the types chosen
ColumnTypeNULL
idBIGINT0
customerVARCHAR(12)0
paidBOOLEAN1
totalDECIMAL(5, 2)0
placedDATE0
tagsJSONB2
noteVARCHAR(7)2

How to use the JSON to SQL Converter

  1. Paste a JSON array of objects into Your JSON, or load a .json file. One object on its own is accepted as a single row.
  2. Enter a Table name and choose the Database: names, strings and true or false are written differently for each.
  3. Set Rows per INSERT, and untick Include CREATE TABLE if the table already exists.
  4. Check the column table under the script, then press Copy or Download .sql.

How do I convert JSON to SQL INSERT statements?

Each object in the array becomes one row and each key becomes a column. The columns are the keys of all objects in the order they first appear, so an object that lacks a key simply gets NULL in that column. In the sample the second order has a note and the others do not, and the first has tags that the others lack. The second INSERT reads: INSERT INTO "orders" ("id", "customer", "paid", "total", "placed", "tags", "note") VALUES (2, 'O''Brien', false, 80, '2026-03-15', NULL, 'C:\temp'); The third row carries no note and no tags, which is why it ends in two NULL values.

Values are written by their JSON type. Numbers are copied exactly as typed. Strings and dates go between single quotes, and an apostrophe inside a string is written twice so the statement still parses. The first row comes out as INSERT INTO "orders" ("id", "customer", "paid", "total", "placed", "tags", "note") VALUES (1, 'Ada Lovelace', true, 129.5, '2026-03-14', '["gift","express"]', NULL); Setting the batch to 10 or 100 rows merges neighboring objects into one statement with several groups, and it starts with INSERT INTO "orders" ("id", "custome... and then has one indented group per row.

Nested objects and arrays do not fit one cell, so they are stored as compact JSON text. The tags array ["gift","express"] is written as '["gift","express"]'. A column that holds only nested values gets a JSON type where the database has one, and plain text where it does not.

How are column types chosen from JSON values?

The type comes from every value in the column, not from the first one. Whole numbers of up to 18 digits give BIGINT, and numbers with a decimal point give DECIMAL with the digits they need: the totals 129.5, 80 and 0.25 need 5 digits in all with 2 after the point, so the column is DECIMAL(5, 2). A number such as 1e3 gives a floating point type, and an integer longer than 18 digits, like 12345678901234567890, gives DECIMAL(20, 0).

Booleans give a boolean type, strings that are real calendar dates written as YYYY-MM-DD give DATE, and other strings give VARCHAR sized to the longest value, or TEXT above 4000 characters. A column that mixes kinds, for example 1, "a" and true, becomes text and every value is written as a string. In INSERT INTO "orders" ("v") VALUES ('1'); INSERT INTO "orders" ("v") VALUES ('a'); INSERT INTO "orders" ("v") VALUES ('true'); the number and the boolean are both quoted. The page tells you when this happens. A date that does not exist, such as 2026-02-30, stays text.

The types are a starting point. Check them against what your table needs, and change a VARCHAR length or a DECIMAL scale before you run the script on real data.

Column types chosen for the sample (PostgreSQL)
ColumnTypeNULL values
idBIGINT0
customerVARCHAR(12)0
paidBOOLEAN1
totalDECIMAL(5, 2)0
placedDATE0
tagsJSONB2
noteVARCHAR(7)2

What differs between PostgreSQL, MySQL, SQLite and SQL Server?

Three things change in the output. Names are quoted with double quotes in PostgreSQL and SQLite, backticks in MySQL and square brackets in SQL Server. MySQL also doubles every backslash inside a string, so C:\temp is written as 'C:\\temp' there. SQL Server puts an N before a string that has characters outside plain ASCII, so Zoë Müller gets that prefix and O'Brien does not.

Booleans differ as well. SQL Server has no true or false literal, so its BIT column takes 1 and 0. SQLite stores Boolean values as the integers 1 and 0, so the page writes those. PostgreSQL and MySQL accept true and false. For nested values PostgreSQL gets JSONB, which it documents as the type to prefer for most uses, MySQL gets its JSON type and the other two get text.

The same sample written for each database
DatabaseType of paidValue of paid in row 1Type of tagsText: Zoë Müller
PostgreSQLBOOLEANtrueJSONB'Zoë Müller'
MySQLBOOLEANtrueJSON'Zoë Müller'
SQLiteINTEGER1TEXT'Zoë Müller'
SQL ServerBIT1NVARCHAR(MAX)N'Zoë Müller'
Standard SQLBOOLEANtrueTEXT'Zoë Müller'

What if the JSON to SQL converter gets something other than an array of objects?

Each item must be an object because its keys name the columns. A list of plain values such as [1, 2] cannot be turned into rows, and the page says so: "Item 1 is not an object. Each item of the array must be an object such as {"id": 1}, because its keys become the columns." A single object is accepted and gives one row. Invalid JSON is stopped before any SQL is written, with the position of the mistake, so [{"a":1},] gives: Not valid JSON. Line 1, column 10: A trailing comma before ] is not allowed in JSON.

Keys that differ only by letter case, such as id and ID, would be one column in most databases, so the page warns before you run the script. Data that starts as a spreadsheet export belongs in the CSV to SQL converter instead, which reads delimiters and header rows.

Use it with

Questions

How do I convert JSON to SQL?

Provide an array of objects and a table name, then choose a database. Keys become columns and each object becomes an INSERT, for instance INSERT INTO "orders" ("id", "customer", "paid", "total", "placed", "ta...

What happens to nested objects and arrays?

They are stored as compact JSON text in one column. PostgreSQL gets JSONB, MySQL gets JSON and SQLite and SQL Server get text columns.

What if some objects have fewer keys?

The columns are the union of all keys. A key that an object does not have is written as NULL, and the page counts those values.

How are quotes and apostrophes escaped?

A single quote inside a value is repeated, which turns the surname into 'O''Brien'. For MySQL each backslash is repeated too, and SQL Server marks non-ASCII text with a leading N.

Why is my number column text?

A column becomes text when it mixes numbers with strings or booleans. Make the values the same kind in the JSON to get a number type.

Is my JSON uploaded?

No request is made with your data. A script running in this tab reads the JSON and writes the SQL, then the result is yours to copy.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.