JSON Array to SQL INSERT: Generate Insert Scripts from Objects

2026-07-22

Why convert JSON to SQL

API responses and mock files are often object arrays, while test databases need INSERT rows. Quoting by hand is slow. ComTools JSON to SQL (Tools/Json/ToSql) builds INSERT statements locally in the browser.

If your data lives in Excel/CSV, prefer full-featured Excel to SQL (dialects, batch INSERT, UPDATE/DELETE).

Input rules

Rule Details
Root type Prefer an array of objects; a single object is treated as one row
Columns Keys from the first object
Empty array Emits -- No rows
Table name Defaults to MyTable—replace before running

Value mapping

JSON SQL
null / missing NULL
number Unquoted
string / other Quoted; '''

Steps

  1. Open JSON to SQL.
  2. Paste a JSON array (validate / format first if needed).
  3. Click Run and copy the INSERTs.
  4. Replace MyTable with the real name; run on a test database.

Example

Input:

[
  { "Id": 1, "Name": "Alice", "City": "Beijing" },
  { "Id": 2, "Name": "O'Brien", "City": null }
]

Output sketch:

INSERT INTO MyTable (Id, Name, City) VALUES (1, 'Alice', 'Beijing');
INSERT INTO MyTable (Id, Name, City) VALUES (2, 'O''Brien', NULL);

Common scenarios

Scenario Approach
Seed test DB from API sample Paste response array → SQL
Sync frontend mocks to DB Same
Large Excel import Excel to SQL
IN-list only Text to SQL
Few pasted rows Generate INSERT

vs Excel to SQL

Capability JSON to SQL Excel to SQL
Input JSON text xlsx / csv upload
Statement types INSERT-focused INSERT / UPDATE / DELETE / SELECT
Dialects Generic INSERT text SQL Server / MySQL / PostgreSQL / …
Batch multi-row INSERT No (one statement per row) Yes
Where it runs Browser local Server parses files

Notes

  • Extra keys on later objects are ignored unless present on the first object—keep a consistent shape.
  • Booleans may appear as quoted text; adjust for bit columns if needed.
  • Nested objects/arrays are poor INSERT candidates—flatten first.
  • Back up production; verify row counts on test first.

FAQ

Change table name?
Replace MyTable in the output.

UPDATE/DELETE?
Use Excel to SQL.

Non-English column names?
Allowed; align with DB fields or rename after generation.


中文版