Boneyard Tools

SQL to JSON examples

Common INSERT shapes and the JSON they produce, including NULLs, multiple rows and quoted identifiers.

Rows become objects

Each value tuple in an INSERT becomes one JSON object. The column list supplies the keys, so INSERT INTO users (id, name) VALUES (1, 'Ada') produces { "id": 1, "name": "Ada" }. Several tuples in one statement, or several statements, all flatten into a single array.

Values keep their types

Numbers stay numbers, NULL becomes JSON null, and TRUE and FALSE become booleans. Text wrapped in single quotes becomes a JSON string, with a doubled quote ('') decoded back to a single quote. Large integers that cannot be represented exactly as a JavaScript number are returned as strings so no digits are lost.

Quoted and dotted identifiers

Double-quoted, backtick and bracketed column names are all supported, so a column like "First Name" keeps its spaces in the JSON key. Schema-qualified table names such as public.users are handled too, and SQL comments are stripped before parsing.

Frequently asked questions

Can I feed it a database dump?

Yes. Paste the INSERT statements from a mysqldump or pg_dump file. CREATE TABLE and other non-INSERT statements are skipped, and only the row data is converted.