SQL to JSON Converter – Free, Online, Private
Read INSERT statements and print a JSON array of rows. Column lists become object keys. A statement without columns becomes arrays of values.
How to convert SQL to JSON
- Paste one or more INSERT INTO ... VALUES statements.
- Rows are collected across statements into one JSON array.
- Copy the JSON. Strings, numbers, TRUE, FALSE and NULL are decoded.
Which SQL this reads
The parser looks for INSERT INTO name (columns) VALUES (...), (...). The table name may be quoted with double quotes, backticks or brackets. Several tuples after one VALUES keyword become several objects. A later INSERT in the same paste is appended. When the column list is present, each tuple becomes an object. When it is omitted, each tuple becomes a JSON array, because there are no names to use as keys. SELECT results, COPY output and CREATE TABLE are not row data and are rejected with an error rather than half-parsed.
Literals
NULL, TRUE and FALSE are recognized case-insensitively. Integers and decimals become JSON numbers. Single-quoted strings use the SQL rule that two quotes are one quote. A string that itself contains JSON object or array text is parsed into a nested value, which is how this site's own JSON-to-SQL output round-trips nested fields. Other strings stay strings. Identifiers in the column list lose their quotes. The parser does not evaluate expressions, casts, or functions. VALUES (now()) is not executed; it will not become a timestamp.
Worked example
The sample insert names id, name and active. Two tuples become two objects. Ada's active flag is true and Grace's is false because TRUE and FALSE were booleans, not strings. The table name users is not part of the JSON. If you need it, keep it in a wrapper yourself. A second INSERT INTO users ... in the same box would add more objects to the same array. That is convenient for a dump script and surprising if you pasted two unrelated tables. Split the paste when the tables differ.
Why a local parser
Insert scripts are a common way a staging database is shared. Pasting one into a website that uploads the text is a bad default. This page tokenizes the statement in the browser and prints JSON you can then convert to CSV or YAML with the other tools here. It is a reader for literals, not a database engine, so it will not tell you that a foreign key is missing.
Frequently asked questions
Does it run the SQL?
No. It only reads INSERT literals. Functions, subqueries and SELECT lists are out of scope.
Can there be multiple statements?
Yes. Every INSERT's rows are concatenated into one JSON array.
What if there is no column list?
Each tuple becomes a JSON array of values instead of an object.
Are quotes handled?
A doubled single quote inside a string is one quote character, which is standard SQL.