SQL to JSON
Turn SQL query results (MySQL, psql or copied grids) or INSERT statements into JSON.
Runs in your browser
Output will sizzle here.
From query results to JSON
You ran a query and need the rows as JSON: for a test fixture, an API mock, a bug report or a quick script. Copy the output the way it came and paste it here. MySQL's boxed tables (+----+), psql's aligned output, tab-separated rows copied from DBeaver, SSMS, DataGrip or pgAdmin, and INSERT … VALUES statements are all recognised automatically.
Each row becomes an object keyed by column name. NULL becomes null. With Detect numbers and booleans on, 42 becomes a number and true or psql's t a boolean, while values like 01234 or 9.50 stay text so nothing is lost; quoted values from INSERT statements always stay text.
How to use the SQL to JSON
Copy the results. From the mysql or psql command line, a SQL tool's results grid (select all, copy), or a dump with INSERT statements.
Paste them here. The format is detected and shown under the box.
Check the types. Turn off Detect numbers and booleans to keep every value as text.
Use the JSON. Copy it, or send it on to JSON to Types, the Schema Validator or JSON Diff.
Tips
- In psql,
\pset format aligned(the default) gives output this tool reads; for wide results, avoid\xexpanded mode. - Integers too big for JavaScript, like 64-bit IDs, are kept as text so their digits stay exact.
- Going the other way? JSON to SQL turns JSON rows into INSERT statements.
Frequently asked questions
Which formats are recognised?
MySQL and MariaDB command-line tables, psql aligned output (with or without the row count), tab-separated rows with a header row, and INSERT INTO … VALUES statements with one or many rows.
How are NULLs shown?
NULL, <null>, (null) and [NULL] become JSON null. In psql output, an empty cell is NULL, since that's how psql shows it.
Why is 9.50 still a string?
Because turning it into the number 9.5 would change how it's written. Values that can't round-trip exactly are left as text.
Is my data uploaded?
No. It's converted in your browser.