SQL Insert to JSON
Read INSERT statements back into a JSON array of objects, with strings, numbers, NULL and booleans typed.
What INSERT to JSON does
The statements are tokenized first, so a value may contain a semicolon, a comma, a parenthesis or a doubled quote and still be one value; a comment contributes nothing. Values keep their type: a quoted string becomes a string, a bare number becomes a number, NULL becomes null, TRUE and FALSE become booleans. A value that is a function call rather than a literal is returned as its source text, because a JSON tree cannot hold "call this function" and pretending it was the string would be worse. One table per run: a dump with several is refused by name rather than merged.
How to use it
SQL Insert to JSON: paste the SQL into the box above, and press Run to get the JSON below.
Worked example
Input:
INSERT INTO users (id, name, role) VALUES
(1, 'Ada', 'admin'),
(2, 'O''Brien', 'author'),
(3, 'Grace', NULL);
Output:
[
{
"id": 1,
"name": "Ada",
"role": "admin"
},
{
"id": 2,
"name": "O'Brien",
"role": "author"
},
{
"id": 3,
"name": "Grace",
"role": null
}
]
Why it runs in your browser
The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads SQL and returns JSON; reloading the page discards both.
The statements are tokenized first, so a value may contain a semicolon, a comma, a parenthesis or a doubled quote and still be one value; a comment contributes nothing. Values keep their type: a quoted string becomes a string, a bare number becomes a number, NULL becomes null, TRUE and FALSE become booleans. A value that is a function call rather than a literal is returned as its source text, because a JSON tree cannot hold "call this function" and pretending it was the string would be worse. One table per run: a dump with several is refused by name rather than merged.
Read INSERT statements back into a JSON array of objects, with strings, numbers, NULL and booleans typed.
How to use it
SQL Insert to JSON: paste the SQL into the box above, and press Run to get the JSON below.
Why it runs in your browser
The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads SQL and returns JSON; reloading the page discards both.
What to Expect
Best for
- Converting SQL to JSON when the data is already on screen.
What this tool keeps
- Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.
Sample input
INSERT INTO users (id, name, role) VALUES (1, 'Ada', 'admin'), (2, 'O''Brien', 'author'), (3, 'Grace', NULL);
Sample output
[ { "id": 1, "name": "Ada", "role": "admin" }, { "id": 2, "name": "O'Brien", "role": "author" }, { "id": 3, "name": "Grace", "role": null } ]
Frequently asked questions
How do I use the sql insert to json?
SQL Insert to JSON: paste the SQL into the box above, and press Run to get the JSON below.
Is my input uploaded?
No. The text is parsed on this page with JavaScript and is never posted to a server.
Is there a size limit?
Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.