How to Export SQL Query Results to JSON
Use database-side JSON functions for repeatable exports, and the browser converter when you only have a one-off result set.
If your database has native JSON functions, use them. They run on the server, they handle types, and they avoid the cost of round-tripping through CSV. The browser tool is for the case where you already have query output and just need to reshape it.
1. Postgres: row_to_json or json_agg
SELECT json_agg(t)
FROM ( SELECT id, name, created_at FROM users ORDER BY id
) t;json_agg returns a JSON array. row_to_json wraps a single row. Combine the two when you want one row per object inside an array.
2. MySQL: JSON_OBJECT and JSON_ARRAYAGG
SELECT JSON_ARRAYAGG( JSON_OBJECT( 'id', id, 'name', name, 'created_at', created_at )
)
FROM users;JSON_OBJECT is explicit about which columns end up in the output, which is useful when you do not want to expose internal column names.
3. SQLite: json_object and json_group_array
SELECT json_group_array( json_object('id', id, 'name', name)
) FROM users;Same idea, different function names. SQLite's JSON1 extension is built in for modern SQLite versions.
When to switch to the browser tool
If you already have query output as a SQL INSERT dump, a flat result set, or a copy from a SQL client, the database-side approach is overkill. Use SQL to JSON. It accepts the common SQL output shapes and emits JSON arrays without making you rewrite the query.
For the broader topic, browse the Data Conversion Tools hub. If your goal is to compare two snapshots, send the JSON to JSON Diff.