Back to Tools

SQL to JSON Converter

Transform SQL SELECT statements or query results into structured JSON data

CONVERTER PRO
SQL Query
JSON Representation

                

Describe a SELECT statement as JSON

Sometimes you need a query's structure in a form a program can read: which table does it hit, which columns does it ask for, and what was the original text? SQL to JSON pulls those pieces out of a SELECT statement and returns them as a small JSON document you can drop into a config file, a test fixture or a documentation snippet.

How to convert a query

  1. Paste a SELECT statement into the SQL Query box. Sample loads a short example selecting four columns from users.
  2. Click Convert to JSON Structure.
  3. Read the JSON Representation panel and press Copy to take it.

For the sample query, the output has three fields: table, set to users; columns, an array with id, username, email and role; and query, holding the original SQL text with surrounding whitespace trimmed. The JSON is indented with four spaces.

What this tool is, and is not

It describes a query; it does not run it. No database is contacted, so you will not get rows of results back as JSON. If you want to convert actual data, export the result set from your database client instead. The extraction is done with pattern matching on the text between SELECT and the first FROM, and on the first word after FROM.

Practical uses

  • Recording the column list of a report query in a metadata file.
  • Feeding a simple query description into a script that builds documentation.
  • Checking which columns a colleague's query returns, one item per line.
  • Creating sample data for a front-end component that displays query definitions.

Cases where it will fail or mislead

The pattern expects the column list to sit on the same line as the word SELECT, so a query with one column per line produces the message that it could not parse the SQL structure; put the columns on one line first, or run the query through a minifier. Columns are split at every comma, which breaks function calls with several arguments such as COALESCE(a, b) into separate entries. Aliases stay attached to their column text. The table value is only the first word after FROM, so schema-qualified names like public.users return only the schema part, and joins, subqueries or multiple tables are not represented. Only SELECT statements are meant to be converted. Everything runs in your browser.


Related Tools

Related Tools


Frequently Asked Questions

Does the tool return the data from my query?
No. It never executes SQL. The JSON contains only the table name, the column list and the original query text. To get actual rows as JSON, export the query results from your database client.
Why do I get an error saying the SQL structure could not be parsed?
The tool expects a SELECT ... FROM pattern with the column list on the same line as SELECT. Statements that are not SELECT, or column lists spread over several lines, are rejected. Rewriting the query on fewer lines usually fixes it.
How does it handle SELECT *?
The columns array will contain a single item, the asterisk. The tool cannot know the real column names because it has no access to your table definition, only the text you pasted.
What happens with joins or several tables?
Only the first word after FROM is reported as the table, so joined tables are not listed separately. A schema-qualified name such as public.users is cut at the dot and returns just public.
Are functions with commas in the column list handled?
Not reliably. The column text is split at every comma, so COALESCE(a, b) becomes two entries. Check the columns array against your query and correct any split expressions by hand.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.