Format Code Now
/
ConvertSQL INSERT to JSON Next: SQL INSERT to YAML ›

SQL INSERT to JSON Converter

CV-107

Paste INSERT ... VALUES statements and get JSON: an array of objects keyed by column name. Numbers keep every digit.

Runs in your browser. Nothing is uploaded.

SQL INSERT statements (optional first line: -- table: name)

JSON

How to use it

  1. Paste your SQL INSERT statements.
  2. Pick the string escape style and the indent.
  3. Press SQL to JSON.
  4. Copy or download the JSON.

Types in the JSON

Strings become JSON strings, NULL becomes null, TRUE and FALSE become booleans, and numbers are written with the exact digits from the SQL. Only what JSON demands is tidied: a leading + or extra zeros are removed, and .5 becomes 0.5. A 1234567890123456789.50 stays exactly that. Hex values such as 0x1F, and expressions such as NOW(), are kept as text because nothing is evaluated. Rows that name different columns are merged, with null where a column was not given.

One table or several

One table gives an array of objects. If the SQL inserts into several tables, the result is an object with one array per table name, such as "dbo.Customers". Put -- table: name on the first line to get just one table as an array. Statements other than INSERT ... VALUES are skipped, and INSERT ... SELECT is an error. Without a column list the keys are column_1, column_2 and so on.

Error messages and what to do

MessageWhat it meansFix
No INSERT ... VALUES statements foundThe text has no INSERT with a VALUES list.Paste INSERT INTO ... VALUES (...) statements.
A quoted string is never closed at line 1A string starts with a quote and does not end.Close the quote, or use the MySQL setting if backslashes escape quotes.

Questions people ask

How do I convert SQL INSERT statements to JSON?

Paste the statements and press SQL to JSON. Each row in VALUES becomes an object whose keys are the column names. Copy the array or download the .json file.

What happens to NULL and booleans?

NULL becomes JSON null, and TRUE and FALSE become true and false. A 0 or 1 that you wrote as a number stays a number, since the tool cannot know it meant a boolean.

Are decimals and big integers exact?

Yes. The digits are copied from your SQL, not converted through a floating-point value, so an ID with 19 digits or a price with many decimals comes out unchanged.

Why is a value a string like "NOW()"?

Functions and expressions are not evaluated, so their text is kept as a string. The same goes for hex literals. Replace them with real values before converting if you need data types.

Does it support T-SQL and PostgreSQL syntax?

Yes for the INSERT forms: [bracket] and "quoted" names, N'text' strings and multi-row VALUES. Use the MySQL setting for backslash escapes. Other statements, such as SET IDENTITY_INSERT, are skipped.

About this tool

Only INSERT ... VALUES statements are read, including multi-row inserts and the quoted-name styles of SQL Server, PostgreSQL and MySQL. Every other statement (CREATE TABLE, UPDATE, SET and so on) is skipped, and INSERT ... SELECT is an error. Without a column list the columns are named column_1, column_2 and so on. Numbers are kept digit for digit, so a 19-digit ID is not rounded. A value that is a function or expression, such as NOW() or CURRENT_TIMESTAMP, is kept as its text, since nothing is evaluated. One table gives an array of objects; several tables give an object with one array per table name, unless you choose one with -- table: name on the first line. Strings, numbers, TRUE and FALSE, and NULL become the matching JSON types, and a number is written with the exact digits from the SQL (only a leading + or zeros and a bare .5 or 5. are tidied to valid JSON), so large numbers and 1234567890123456789.50 keep every digit. A hex value such as 0x1F or X'1F' is kept as text. Rows that name different columns are merged, with null where a column was not given. The MySQL option reads backslash escapes inside strings; Standard is right for SQL Server, PostgreSQL and SQLite.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.