What JSON to SQL does
JSON to SQL reads JSON and writes it as SQL. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.
JSON is the standard text format for structured data in APIs and configuration files: objects, arrays, strings, numbers, true, false and null. SQL INSERT statements add rows to a database table. Running them in MySQL, PostgreSQL, SQLite or SQL Server loads the data.
JSON to SQL example
Input
[{"id":1,"name":"Ada","city":"London"},{"id":2,"name":"Lin's","city":null}]Output
-- Table name: data. Rename it to match your database.
INSERT INTO data ("id", "name", "city") VALUES (1, 'Ada', 'London');
INSERT INTO data ("id", "name", "city") VALUES (2, 'Lin''s', NULL);The output is what this tool produces for the input above it.
How it works
Reading JSON. The input is parsed as JSON. An array of objects gives one row per object; a single object gives one row.
Writing SQL. Each record becomes one INSERT INTO data (...) VALUES (...); statement. Column names are the keys of the records, with nested objects flattened into dotted names and quoted as identifiers. Text is put in single quotes with any single quote doubled, numbers are written as numbers, true and false become TRUE and FALSE, and missing values become NULL.
Details and limits
- Everything runs on your device, so there is no upload and no fixed size limit; very large inputs depend on its memory.
- It works in current browsers on phones, tablets and computers, and it is free with no account.
- The table is named
data. Change the name, and add aCREATE TABLEstatement if the table does not exist yet. - Numbers are detected only when the whole value is a plain number such as 42 or 3.5.
Questions
Is my data uploaded?
No. The conversion runs in your browser.
Is JSON to SQL free?
Yes, with no sign-up and no limit on use.
Which databases accept the output?
MySQL, MariaDB, PostgreSQL, SQLite and SQL Server all accept these INSERT statements. Column names are in double quotes, the SQL standard; in MySQL, turn on ANSI_QUOTES or replace them with backticks.
Can I convert SQL back to JSON?
Not with this tool. To get rows out of a database, export the query result as CSV or JSON from your database client.