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
- Open JSON to SQL.
- Paste a JSON array (validate / format first if needed).
- Click Run and copy the INSERTs.
- Replace
MyTablewith 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
bitcolumns if needed. - Nested objects/arrays are poor INSERT candidates—flatten first.
- Back up production; verify row counts on test first.
Related posts
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.