logo
GeekFormat

SQL Converter

GeekFormat's online SQL Converter turns SQL INSERT statements and CREATE TABLE scripts into JSON, CSV, TSV, XML, YAML, HTML tables, Markdown tables, JSON Lines and more in a single click. It supports multiple INSERT statements and multi-value tuple parsing, automatically recognizes numbers, strings, NULL, booleans and hexadecimal literals, and is compatible with the quoting styles of MySQL, PostgreSQL, SQLite and SQL Server. Data from multiple tables can be exported separately or merged together. You can also rebuild INSERT statements in a different dialect. All processing happens locally in your browser—your data never leaves your device.

Related

About SQL conversion: turning SQL scripts into JSON/CSV/XML and other formats

SQL conversion is the process of extracting data from a SQL script and reorganizing it into other data formats such as JSON, CSV, XML, YAML, HTML and Markdown. SQL (Structured Query Language) is the standard query language for relational databases, and database export tools (such as mysqldump and pg_dump) typically export data as INSERT statements in a SQL script. While this format is convenient for database imports, it is not convenient for programs to read, for data analysis or for cross-system exchange—so it often needs to be converted into more universal formats.

A typical SQL data export script contains two kinds of statements: CREATE TABLE defines the table structure (column names, data types, constraints), and INSERT INTO ... VALUES (...) inserts the actual data. This tool parses both kinds of statements—extracting column definitions and type information from CREATE TABLE and actual data rows from INSERT—and then reorganizes them according to the format you choose. The entire parsing process runs locally in your browser and does not depend on any back-end service.

Why convert SQL into other formats? Although SQL is universal, it is inconvenient in these scenarios: first, front-end programs find it far easier to read JSON than to parse SQL, with no need for a SQL parser; second, spreadsheet tools such as Excel and Google Sheets natively support CSV rather than SQL; third, in configuration-file and documentation contexts YAML and Markdown are more readable than SQL; fourth, cross-system data exchange often uses XML or JSON as a neutral format. Converting SQL into these universal formats lets the data be consumed directly by more tools and languages.

The SQL parser in this tool is hand-written and focused on INSERT and CREATE TABLE statements. For INSERT, it supports both single-value tuples (INSERT INTO t (a,b) VALUES (1,2)) and multi-value tuples (INSERT INTO t (a,b) VALUES (1,2), (3,4), (5,6)), automatically mapping data by column name. For CREATE TABLE, it parses column definitions, data types (VARCHAR(255), INT, DECIMAL(10,2) with parenthesized lengths), NOT NULL, PRIMARY KEY, IF NOT EXISTS and other constraints and clauses, correctly handling nested parentheses to avoid incorrect splitting.

Type recognition is the key to SQL conversion. The tool automatically infers the type from the literal form of a value: anything wrapped in single or double quotes is a string; NULL (case-insensitive) is the null value; TRUE/FALSE is a boolean; 0x..., X'...', B'...' are hexadecimal literals; and a pure number (with optional sign, decimal point or scientific notation) is a number. This automatic type recognition ensures that converted JSON, CSV and other formats preserve the original data semantics (the number 1 is not the string "1"), so downstream programs can handle it correctly.

Differences in quoting styles between database dialects are a common pitfall in SQL parsing. MySQL wraps identifiers (table names, column names) in backticks (`), PostgreSQL uses double quotes ("), SQL Server/T-SQL uses brackets ([]), and standard SQL also uses double quotes. The tool's unquoteIdentifier function automatically recognizes and strips these quotes and handles escapes inside them (`` → `, "" → "). In SQL rebuild mode, INSERT statements can be regenerated with the quote style of the target dialect.

SQL string escaping is another key technical point. The SQL standard escapes a single quote inside a string by doubling it ('It''s' represents It's), while MySQL also supports backslash escaping (\n, \t, \', \", \\, \0, \Z, etc.). The tool's string parser handles both escape mechanisms to correctly restore the original string content. When converting to CSV, fields containing commas, quotes or newlines are re-escaped per RFC 4180; when converting to XML/HTML, special characters such as &, <, >, " and ' are escaped.

Pure front-end processing is the core design principle of this tool. All SQL parsing and data conversion run in your browser's JavaScript engine, and no data is sent to any server. This means that even if your SQL script contains user privacy, commercially sensitive information or internal database structures, nothing leaks externally. This design is particularly suitable for processing production database exports, with no data-compliance concerns. Front-end processing also has no network latency, so conversion speed is limited only by your device's CPU and memory.

Compared with traditional command-line SQL conversion tools (such as sql2csv and sqlparser), this tool has several advantages: no installation or environment configuration is required—just open the page and start using it; it provides a visual interface with a real-time preview of the conversion result; it supports multiple output formats that switch with one click; it ships with sample data and built-in help; and its mobile-responsive design lets you use it anywhere. In exchange, the tool focuses on data extraction and does not handle complex dialect differences (such as PostgreSQL's JSONB operators or MySQL's ON DUPLICATE KEY UPDATE) or advanced features (stored procedures, functions, triggers). For such needs, use native database tools or a dedicated ETL platform.

When using a SQL conversion tool, a few best practices are worth noting: first, before converting, check that your SQL script contains actual data (INSERT statements) rather than only queries (SELECT)—SELECT is not parsed; second, for scripts with multiple tables, enable "Output tables separately" to preserve table structure information; third, when processing SQL that contains Chinese, enable "Include BOM" in CSV output to ensure Excel recognizes the encoding; fourth, when processing large SQL dumps, turn off "Pretty-print output" to reduce output size; fifth, when migrating across databases, use "SQL rebuild" mode to switch dialects, but complex types (such as PostgreSQL arrays and JSONB) may need manual adjustment.

Use Cases

  • Convert SQL scripts exported by mysqldump or pg_dump into JSON for API data import or front-end consumption.
  • Turn database INSERT statements into CSV files for analysis or reporting in Excel/WPS/Google Sheets.
  • Extract data from SQL backup scripts into XML for cross-system data exchange or SOAP integration.
  • Convert SQL data into YAML configuration format for Ansible, Docker Compose, Kubernetes and other config scenarios.
  • Convert SQL query results (exported as INSERT) into HTML tables that can be embedded directly into web pages.
  • Turn SQL data into Markdown tables to paste into README files, documentation sites or technical blog posts.
  • Extract data from a full CREATE TABLE + INSERT script into JSON Lines for Elasticsearch bulk indexing.
  • During database migration, rebuild MySQL INSERT scripts into PostgreSQL-dialect INSERT statements for cross-database import.
  • Test data management: turn SQL seed data into JSON configuration that programs can easily read and version control.
  • Teaching demos: convert SQL statements into multiple formats to help learners understand the differences between data representations.
  • ETL preprocessing: turn upstream SQL dumps into structured JSON/CSV as input for downstream ETL pipelines.
  • Data analysis: extract key data from SQL exports into CSV and analyze it with pandas, R and other tools.
  • Client delivery: convert database exports into more universal JSON or CSV formats for non-technical stakeholders.
  • Data archiving: convert INSERT scripts from legacy databases into more readable YAML or Markdown archives.

How to Use

  1. Paste your SQL script into the input box on the left, or click the "Upload SQL" button to select a .sql/.txt file.
  2. Click the "Example" button to load a built-in SQL sample (with CREATE TABLE and multi-table INSERT).
  3. Choose the target format (JSON, CSV, XML, YAML, etc.—9 options) from the format dropdown at the top of the right output panel.
  4. Click the "Settings" button to adjust conversion options: pretty-print output, include BOM, output tables separately, CSV delimiter, JSON root key name, SQL dialect, and more.
  5. Click the "Convert" button to run the conversion. The result appears in the right panel, with the bottom status bar showing table count, row count, INSERT count and other statistics.
  6. Click "Copy" to copy the result to the clipboard, or click "Download" to save it as a file in the corresponding format (e.g. result.json, result.csv).
  7. Switching the output format re-runs the conversion automatically—you don't need to click Convert again.

Features

  • Nine output formats: JSON, JSON Lines, CSV, TSV, XML, YAML, HTML table, Markdown table and SQL rebuild—switch the format and the conversion re-runs automatically.
  • INSERT statement parsing: recognizes INSERT INTO ... VALUES (...) syntax and supports both single-row and multi-value tuple batch inserts (multiple rows in a single INSERT).
  • CREATE TABLE recognition: parses CREATE TABLE statements to extract column definitions, data types, NOT NULL, PRIMARY KEY and other constraints, useful for inferring field types.
  • Multi-table data handling: when a script contains multiple tables, you can export them separately (with table name separators) or merge them, automatically aggregating the columns and rows of each table.
  • Automatic type recognition: intelligently recognizes numbers (integers/floats), strings, NULL, booleans (TRUE/FALSE) and hexadecimal literals (0x..., X'...', B'...'), preserving the original type semantics.
  • Multi-dialect quote compatibility: recognizes MySQL backticks (`), PostgreSQL double quotes ("), SQL Server brackets ([]) and standard quotes, and automatically strips identifier quotes.
  • SQL string unescaping: handles SQL standard escaping ('' → ') and MySQL backslash escaping (\n, \r, \t, \0, \', \") to correctly restore strings that contain special characters.
  • SQL dialect rebuilding: regenerate INSERT statements in MySQL, PostgreSQL, SQLite or standard SQL dialects, with customizable table names and optional CREATE TABLE generation.
  • Flexible CSV options: choose the delimiter (comma/semicolon/Tab/pipe), whether to include a UTF-8 BOM header (Excel compatible), and whether to pretty-print indentation, fully RFC 4180 compliant.
  • Multiple JSON structures: choose between grouped-by-table (tables root key), pure data (data root key) or plain array (no root key) output structures to fit different consumption scenarios.
  • Real-time statistics: after conversion, the tool shows the number of parsed tables, total rows, INSERT statements and output characters in real time so you can verify the result.
  • File upload and download: upload .sql/.txt/.csv/.tsv/.json files for direct parsing, and download conversion results as files in the corresponding format (e.g. .json, .csv, .yaml).
  • History management: a built-in history panel on the left automatically saves your most recent SQL inputs so you can quickly reload previous scripts.
  • Mobile responsive: phones automatically switch to a tabbed input/result layout, while desktops use a draggable dual-panel split view, with all interactions available on mobile.
  • Pure in-browser processing: all parsing and conversion runs in browser JavaScript with no server requests, so your SQL data never leaves the device—ideal for database exports containing sensitive information.

FAQ

What formats can SQL be converted to?

This tool supports nine output formats: JSON (structured array), JSON Lines (one JSON object per line), CSV (comma-separated), TSV (tab-separated), XML (a tagged standard XML document), YAML (configuration format), HTML table (styled, viewable directly in a browser), Markdown table (documentation syntax) and SQL rebuild (regenerate INSERT statements in a different dialect). Just switch from the format dropdown on the right to re-run the conversion automatically.

Which SQL statements can be parsed?

It mainly parses INSERT INTO ... VALUES (...) statements to extract data, and recognizes CREATE TABLE statements to capture column definitions and type information. It supports single-row INSERT, multi-value tuple INSERT (multiple rows in one INSERT), multiple INSERT statements and INSERTs across multiple tables. Comments (-- single line, /* */ multi-line, # MySQL single line) are stripped automatically and do not affect parsing.

Which database dialects are supported?

During parsing, the tool is compatible with MySQL (backtick `), PostgreSQL (double quote "), SQL Server (bracket []) and standard SQL identifier quoting styles, and automatically strips quotes to restore the original column and table names. In SQL rebuild mode you can choose MySQL, PostgreSQL, SQLite or standard SQL to regenerate INSERTs; the quotes and boolean representations differ between dialects.

How are SQL scripts with multiple tables handled?

The tool aggregates INSERT data by table name. With "Output tables separately" enabled in settings, table formats such as CSV/HTML/Markdown are exported per table (with table-name markers), while structured formats like JSON/XML are grouped by table name. When the option is off, CSV only outputs the first table, and JSON can be output as a plain array with "no root key".

How are NULL, booleans and special characters in SQL handled?

The tool automatically recognizes NULL (case-insensitive), TRUE/FALSE booleans, hexadecimal literals (0x..., X'...', B'...'), integers and floating-point numbers. Strings are unescaped using both the SQL standard ('' → ') and MySQL backslash escaping (\n, \t, \', etc.), correctly restoring the original content with newlines, quotes and special characters. CSV output follows RFC 4180, quoting fields that contain commas, quotes or newlines.

What does the converted JSON structure look like?

JSON output supports three structures: "tables root key" (grouped by table name, recommended for multi-table scenarios), "data root key" (unified wrapper) and "no root key" (plain array, suitable for a single table or stream processing). For example, a single users table becomes an array like [{"id":1,"name":"Alice"},...], while multiple tables are grouped by name as {"users":[...],"orders":[...]}. You can choose in the settings.

Are uploaded SQL files saved to the server?

No. This is a pure front-end application. All parsing and conversion run in your browser's local JavaScript—no SQL content or conversion results are ever sent to any server. Uploaded files are read directly in the browser via FileReader, and the data is cleared when you close the page. This makes it suitable for database exports that contain user privacy or commercially sensitive information.

Are SQL Server bracket identifiers supported?

Yes. The tool recognizes SQL Server/T-SQL style bracket identifiers (e.g. [users], [order details]) and strips the brackets to restore the original name. MySQL backticks and PostgreSQL double quotes are also supported. In SQL rebuild mode, choosing different dialects regenerates INSERTs with the corresponding quote style.

Why does my SQL script produce no data after conversion?

Check whether your SQL contains INSERT INTO ... VALUES (...) statements. This tool only parses INSERT statements to extract data; SELECT queries produce no output. If only CREATE TABLE statements are present, the tool shows the warning "Only CREATE TABLE detected; no data rows to convert." Make sure your SQL script is a data dump, not a query.

Are stored procedures, functions and triggers supported?

No. This tool focuses on data extraction and only parses INSERT and CREATE TABLE statements. Database object definitions such as stored procedures (CREATE PROCEDURE), functions (CREATE FUNCTION), triggers (CREATE TRIGGER) and views (CREATE VIEW) are not parsed. To migrate these objects, use native database tools such as pg_dump or mysqldump.

Will the converted CSV file display Chinese correctly in Excel?

Yes. With "Include BOM" enabled in settings, the CSV file carries a UTF-8 BOM header (\uFEFF), and Excel will correctly recognize the encoding and display Chinese and other non-ASCII characters. Without BOM, some Excel versions may show UTF-8 Chinese as garbled text. Modern spreadsheet tools such as Google Sheets and WPS usually recognize UTF-8 correctly without BOM.

Can INSERT statements be rebuilt in reverse from a SQL script?

Yes. Select the "SQL rebuild" output format to regenerate INSERT statements. You can choose the target dialect (MySQL/PostgreSQL/SQLite/standard SQL), customize the table name, and optionally generate a CREATE TABLE statement (with column types INT/BIGINT/FLOAT/VARCHAR/TEXT/BOOLEAN inferred from the data). This is useful for rebuilding a MySQL script in PostgreSQL dialect or renaming a table before re-importing into a database.

What is the difference between JSON Lines and JSON? When should I use JSON Lines?

JSON output is a complete JSON array ([{...},{...}]) that is best when a program loads everything into memory at once. JSON Lines (also called NDJSON) puts one independent JSON object per line, which is ideal for stream processing, big-data imports, the Elasticsearch bulk API, log analysis and similar scenarios where you read line by line without holding everything in memory. The tool lets you switch freely between the two.

Does the conversion preserve the original column order?

Yes. The tool preserves column names in the order specified by the INSERT statement. If the INSERT does not explicitly list column names (e.g. INSERT INTO t VALUES (...)), placeholder column names like col_1, col_2 are generated based on the number of values in the first row. Each table keeps its own column order; when merging exports, tables are presented separately.

How large a SQL file can the tool handle?

There is no hard upper limit in theory—it depends on browser memory. SQL dump files of tens of MB are generally processed smoothly, while very large files (hundreds of MB) may slow down due to insufficient browser memory. For very large files, consider splitting them into smaller batches, or turn off "Pretty-print output" to reduce memory usage. All parsing happens locally in the browser, so there is no network transfer limit.

Troubleshooting

No output data after conversion?

Cause 1: The SQL script only contains SELECT queries. This tool only parses INSERT statements to extract data; it does not execute queries. Solution: Use mysqldump/pg_dump to export data as INSERT statements. Cause 2: The SQL script only has CREATE TABLE and no data rows—the tool will show a warning. Cause 3: The INSERT syntax is non-standard (e.g. missing the VALUES keyword); check the SQL syntax. Cause 4: Everything in the SQL is commented out (-- or /* */); check whether comment markers were mistakenly added.

CSV shows garbled Chinese in Excel?

Excel recognizes CSV as GBK by default, so UTF-8 Chinese appears garbled. Solution: Enable "Include BOM" in Settings; the resulting CSV file will carry a UTF-8 BOM header (\uFEFF), and Excel will recognize the UTF-8 encoding. If you already exported a CSV without BOM, you can use Notepad to save it as "UTF-8 with BOM" before opening in Excel, or open it directly in a modern spreadsheet tool such as Google Sheets or WPS.

Numbers become strings in JSON?

Cause: The numbers in the SQL are wrapped in quotes (e.g. '123' instead of 123), so the tool parses them as strings. Solution: Check whether numbers in the SQL script are quoted and remove the quotes. If the original data really is a string (ZIP codes are often stored as strings, for example), this is expected behavior—preserving the string semantics avoids losing leading zeros (e.g. 01234 will not be parsed as 1234).

Strings with special characters fail to convert?

Cause: Special characters (newlines, quotes, backslashes) in the SQL string are not escaped correctly. This tool supports SQL standard escaping ('' → ') and MySQL backslash escaping (\n, \', etc.), but if the original SQL uses non-standard escaping (such as PostgreSQL's E'...' strings), it may not be restored correctly. Solution: Check that the SQL escaping is standard; if necessary, adjust it manually in a text editor before converting.

Multi-table SQL only shows the first table after conversion?

Cause: The "Output tables separately" option is off, and table formats such as CSV/HTML/Markdown output only the first table by default. Solution: Enable "Output tables separately" in Settings; CSV will be exported per table (with a # Table: table_name marker), and JSON will be grouped by table name ({table1:[...],table2:[...]}). Note that JSON Lines does not distinguish tables—all rows are merged into a single output.

Table or column names have the wrong quotes after SQL rebuild?

Cause: The wrong dialect was selected during rebuild; different dialects use different quote styles (MySQL backticks, PostgreSQL double quotes, SQL Server brackets). Solution: Select the target SQL dialect in Settings; the tool will regenerate INSERTs with the corresponding quote style. For example, with PostgreSQL selected, the table name becomes "users", while with MySQL it becomes `users`.

Glossary

SQL (Structured Query Language)
Structured Query Language, the standard query and manipulation language for relational databases (MySQL, PostgreSQL, Oracle, SQL Server, SQLite). It includes sub-languages such as DDL (data definition), DML (data manipulation), DQL (data query) and DCL (data control).
INSERT statement
A SQL statement that inserts data into a table, with the syntax INSERT INTO table (cols) VALUES (vals). It supports single-row and multi-value tuple batch inserts. This tool primarily parses INSERT statements to extract data.
CREATE TABLE statement
A DDL statement in SQL used to create a table, defining column names, data types and constraints (NOT NULL, PRIMARY KEY, UNIQUE, etc.). This tool can parse CREATE TABLE to extract column-definition information.
VALUES tuple
The list of values in parentheses after the VALUES keyword in an INSERT statement, e.g. (1, 'Alice', TRUE). A single INSERT can contain multiple tuples for batch insertion: VALUES (1,'A'), (2,'B'), (3,'C').
SQL dialect
The different extensions and implementations of the SQL standard by different database vendors, e.g. MySQL uses backticks, PostgreSQL uses double quotes, SQL Server uses brackets to wrap identifiers, and booleans (TRUE/1) and auto-increment columns (AUTO_INCREMENT/SERIAL) also differ.
Identifier quote
A special character in SQL used to wrap identifiers such as table and column names. MySQL uses backticks `name`, PostgreSQL and standard SQL use double quotes "name", and SQL Server uses brackets [name]. They are used for reserved-word escaping or case-sensitive scenarios.
SQL escaping
A mechanism for representing special characters in SQL strings. The SQL standard uses a doubled single quote ('') for a single quote; MySQL also supports backslash escaping (\n, \t, \', \\). This tool restores both escape mechanisms.
NULL value
A special value in SQL representing missing or unknown data, case-insensitive (NULL/null/Null). NULL is not equal to an empty string or 0; it maps to null in JSON and is usually left empty in CSV.
Hexadecimal literal
Literal syntax in SQL for representing binary data. MySQL supports the 0x... and X'...' forms, and PostgreSQL supports X'...' and B'...' (binary). This tool preserves hexadecimal literals as-is.
JSON Lines (NDJSON)
A text format with one independent JSON object per line and the extension .jsonl. It is suitable for stream processing, big-data imports and the Elasticsearch bulk API, and uses less memory than a full JSON array.
RFC 4180
The international standard for the CSV format (Common Format and MIME Type for Comma-Separated Values Files), specifying rules for field separation, quote escaping and newline handling. The CSV output of this tool complies with this standard.
BOM (Byte Order Mark)
Byte Order Mark, the U+FEFF character. A BOM at the start of a UTF-8 file helps software such as Excel recognize the encoding and avoid garbled Chinese. The CSV output of this tool can optionally include a BOM.
SQL Dump
A SQL script file exported from a database, usually generated by tools such as mysqldump or pg_dump. It contains CREATE TABLE and INSERT statements and is used for database backup and migration.
DDL (Data Definition Language)
Data Definition Language, a subset of SQL that includes CREATE, ALTER, DROP and other statements used to define and modify the structure of a database (tables, views, indexes, etc.).

Comparison of supported output formats

Comparison of the features and best-use scenarios of the nine output formats:

FormatExtensionFeatureBest scenario
JSON.jsonStructured array, types preservedAPI integration, program reading, front-end data
JSON Lines.jsonlOne JSON object per lineStream processing, Elasticsearch, big data
CSV.csvComma-separated table, RFC 4180Excel, data analysis, reports
TSV.tsvTab-separated tablePaste into spreadsheet tools, bioinformatics
XML.xmlStructured document with tags and attributesSOAP interfaces, config files, Java systems
YAML.yamlMost readable configuration formatAnsible, K8s, CI/CD configuration
HTML.htmlStyled table, viewable directly in a browserWeb display, email, reports
Markdown.mdMarkdown table syntaxREADME, documentation sites, technical blogs
SQL rebuild.sqlRegenerate INSERT, switchable dialectCross-database migration, table-name changes

SQL value type recognition rules

Type recognition rules when parsing SQL values (judged by literal form):

SQL literalRecognized typeJSON outputCSV output
123Integer123123
-45Negative integer-45-45
3.14Floating point3.143.14
1e10Scientific notation1000000000010000000000
'hello'String"hello"hello
NULLNull valuenull(empty)
TRUEBoolean truetrueTRUE
FALSEBoolean falsefalseFALSE
0xFFHexadecimal"0xFF"0xFF
X'4142'Hexadecimal"X'4142'"X'4142'

Identifier quoting styles by database dialect

Differences in identifier (table name, column name) quoting across major databases:

DatabaseQuote styleExampleNote
MySQL/MariaDBBacktick ``users`On by default, escapes reserved words
PostgreSQLDouble quote ""users"Case-sensitive, standard SQL style
SQLiteDouble quote " / backtick ` / brackets []"users" / [users]Compatible with multiple styles
SQL ServerBrackets [][users]Default T-SQL style
OracleDouble quote ""users"Forces uppercase; quotes preserve case
Standard SQLDouble quote ""users"ANSI SQL standard

Privacy & Security

All operations of this SQL Converter happen entirely in your browser: SQL parsing, data extraction and format conversion all run client-side in browser JavaScript, and no SQL content, uploaded files or conversion results are sent over the network to any server. File uploads use the browser's native FileReader API to read directly into memory, with no intermediate service. No cookies are used for tracking, and no user input or usage data is collected. After closing or refreshing the page, all input and output content is automatically cleared from memory (history is stored only locally in the browser's localStorage). This makes it suitable for processing database export scripts that contain user privacy or commercially sensitive information.

Authoritative References