Convert SQL to JSON
Paste results, parse
INSERTs, get code.
Three modes for every SQL→JSON need: paste query results to get a JSON array, extract JSON from INSERT statements, or get ready-to-run MySQL, PostgreSQL and SQLite export snippets.
Three ways to convert SQL to JSON
Each mode targets a different workflow — choose the one that matches how you're working.
Copy the output of any SQL query from your database client and paste it here. MySQL Workbench, DBeaver, TablePlus and pgAdmin all copy results as tab-separated rows. The converter auto-detects the separator and outputs a JSON array of objects.
id name active 1 Alice 1 2 Bob 0
[{"id":1,"name":"Alice","active":true},
{"id":2,"name":"Bob","active":false}]
Paste INSERT INTO statements from a SQL dump file. The parser extracts column names from the INSERT header and values from each VALUES clause — handling quoted strings, NULL values, escaped quotes and batch INSERTs with multiple value rows.
INSERT INTO users (id, name) VALUES (1, 'Alice'), (2, 'Bob');
[{"id":1,"name":"Alice"},
{"id":2,"name":"Bob"}]
Get ready-to-run SQL queries and code for exporting a table as JSON directly from your database. Covers native JSON functions in MySQL, PostgreSQL and SQLite, plus Node.js and Python patterns for programmatic export.
SELECT json_agg(row_to_json(t)) FROM (SELECT * FROM your_table) t;
When do you need SQL to JSON?
The most common workflows where SQL data needs to become JSON.
API response building
REST APIs return JSON but data lives in SQL databases. Mode 3 gives you the native JSON export query for your database — run it directly and your API endpoint gets a pre-serialised JSON array without any ORM or application-layer serialisation code.
Database migration to NoSQL
Migrating from MySQL or PostgreSQL to MongoDB, Firestore or DynamoDB requires exporting relational data as JSON documents. Mode 1 lets you copy query results and convert them instantly — no mysqldump, no scripting, no intermediate file format.
Reading SQL dump files
SQL dump files contain INSERT statements that are unreadable without a database. Mode 2 parses the INSERT statements and outputs JSON — letting you inspect the data in a JSON viewer, convert it to CSV, or load it into a different system without spinning up a database.
Test data extraction
Development and testing often requires exporting a subset of production data as JSON fixtures. Copy the query results for your test subset in Mode 1 — the JSON array is immediately usable as a fixture file for Jest, Vitest, pytest or any testing framework.
Native JSON export functions by database
The built-in SQL functions for exporting query results as JSON — no application code needed.
| Database | JSON array export | Single row as object |
|---|---|---|
| MySQL 5.7.22+ | SELECT JSON_ARRAYAGG(JSON_OBJECT('id', id, 'name', name)) FROM t |
JSON_OBJECT('id', id, 'name', name) |
| PostgreSQL 9.4+ | SELECT json_agg(row_to_json(t)) FROM (SELECT * FROM t) t |
row_to_json(t.*) |
| SQLite 3.38+ | SELECT json_group_array(json_object('id', id, 'name', name)) FROM t |
json_object('id', id, 'name', name) |
| SQL Server 2016+ | SELECT * FROM t FOR JSON AUTO |
SELECT * FROM t FOR JSON PATH, WITHOUT_ARRAY_WRAPPER |
Exact types: quoted values, 1 and 0, NULL and 64-bit IDs
SQL to JSON should never change your data. Quoted values always stay strings, so '01234' keeps its leading zero; 1 and 0 stay numbers (only the keywords TRUE and FALSE become booleans); NULL becomes null; integers longer than 15 digits stay exact; and semicolons, parentheses and escaped quotes inside strings do not cut a statement.
Working specifically with MySQL? MySQL to JSON handles mysqldump files and mysql -B output and gives you ready-made JSON_ARRAYAGG export queries. To go back from JSON to SQL, use JSON to SQL.
Related JSON tools
SQL converted in
your browser. No database needed.
All three modes run entirely in JavaScript — no connection to any database, no upload to any server. Paste your query results or INSERT statements and get JSON instantly. The code snippets are static — generated from your dialect and table name selection without any API call.
The INSERT parser handles real-world SQL dump syntax: single and batch INSERTs, quoted strings with escaped quotes, NULL values, and mixed spacing. It reads column names from the INSERT header and matches them to values in each VALUES clause.
