Home › Developer Tools › SQL to JSON Converter

SQL to JSON Converter

Paste INSERT INTO statements, optionally with their CREATE TABLE, and get each table's rows as a JSON array of objects. Works with MySQL, PostgreSQL, SQLite and SQL Server syntax, handles multi-table dumps and exports any table as CSV.

Last updated:

Converts automatically as you type. Your SQL is never uploaded or executed.
Advertisement
Advertisement

How to use the SQL to JSON Converter

  1. Paste your SQL: INSERT statements, a full dump, or click Sample. You can also upload a .sql file.
  2. Pick the table to show if the SQL contains more than one, or choose "All tables".
  3. Adjust the options: indentation, booleans, JSON columns and backslash escapes.
  4. Check the status line for skipped statements or errors with their line numbers.
  5. Copy or download the JSON, or export the selected table as CSV.

How SQL values map to JSON

SQL valueJSON valueNotes
'text', N'text', E'text'"text"'' becomes one quote; backslash escapes in MySQL mode and E'' strings
42, -15.50, 1.5e342, -15.5, 1500Integers above 253 − 1 can be kept as strings
NULLnullDEFAULT is also written as null
TRUE / FALSEtrue / false1/0 too, in BOOLEAN, BOOL, BIT(1) and TINYINT(1) columns
'{"a":1}' in a JSON/JSONB column{"a": 1}Needs a CREATE TABLE that declares the column as JSON
'2024-01-15'::date, CAST('5' AS INT)"2024-01-15", "5"The literal inside a cast is used
NOW(), CURRENT_TIMESTAMP"NOW()"Expressions cannot be evaluated, so they are kept as text
X'4A6F', 0x4A6F"0x4A6F", 19055Hex strings stay hex text

Example

INSERT INTO users (id, name, active) VALUES
  (1, 'Ann', TRUE),
  (2, 'O''Brien', NULL);

becomes

[
  { "id": 1, "name": "Ann", "active": true },
  { "id": 2, "name": "O'Brien", "active": null }
]

Tips for database dumps

  • mysqldump writes extended INSERTs without column lists. Keep the CREATE TABLE statements in the input so the JSON gets real column names instead of column1, column2.
  • pg_dump writes COPY blocks by default. Run it with --inserts or --column-inserts to produce INSERT statements this tool can read.
  • SQLite: the .dump command in the sqlite3 shell outputs CREATE TABLE and INSERT statements that convert directly.
  • Statements such as SET, LOCK TABLES, DROP TABLE and CREATE INDEX are ignored safely. The SQL is only parsed, never executed.

Frequently asked questions

What SQL does the converter understand?

INSERT INTO, INSERT IGNORE and REPLACE INTO statements with one or many rows in VALUES, plus CREATE TABLE statements, which are used to name columns and detect boolean and JSON types. Other statements such as SET, LOCK TABLES, DROP or CREATE INDEX in a dump are skipped and counted in the status line.

Where do the JSON keys come from?

From the column list in the INSERT statement, for example INSERT INTO users (id, name) VALUES ... If the INSERT has no column list, the columns of a CREATE TABLE for the same table are used. Without either, keys are named column1, column2 and so on.

How are values converted?

Quoted strings become JSON strings, numbers become JSON numbers, NULL becomes null and TRUE/FALSE become true/false. Values in BOOLEAN, BOOL or BIT(1) columns can be turned from 1/0 into true/false, and JSON or JSONB column values can be parsed into nested objects. Function calls like NOW() are kept as text.

What are backslash escapes?

MySQL treats a backslash inside a string as an escape character, so 'It\'s' means It's and \n means a line break. PostgreSQL, SQLite and SQL Server treat backslashes literally and only use '' to escape a quote. Auto mode turns backslash escapes on when the SQL looks like MySQL, for example when it uses `backtick` quoting.

Can I convert a whole database dump?

Yes. Paste or upload the dump file. Every table with INSERT statements gets its own array; select a table in the menu or choose All tables to get one JSON object keyed by table name. Everything runs locally, so very large dumps are limited only by your browser's memory.

Why are some numbers quoted in the JSON?

Integers larger than 9,007,199,254,740,991 cannot be represented exactly as JSON numbers in JavaScript, so they are kept as strings to preserve every digit. Turn the option off if you prefer plain numbers.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON to SQL ConverterConvert a JSON array of objects to CREATE TABLE and INSERT statements for MySQL, Postgres, SQLite.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.XML to Excel ConverterTurn repeating XML elements into an .xlsx spreadsheet with attributes and nested data as columns.XSD to XML Sample GeneratorGenerate a sample XML document from an XSD schema, with types, attributes and namespaces.YAML to CSV ConverterTurn a YAML list of objects into CSV with dot-notation columns, custom column order and download.DOCX to Markdown ConverterConvert Word .docx to clean Markdown with headings, lists, tables, links and images in a ZIP.ES6 to ES5 ConverterTranspile modern JavaScript (ES2015+) to ES5 with Babel: targets, module format and loose mode.JavaScript Object to JSONTurn JS object literals and Python dicts into valid JSON: quotes keys, fixes commas and values.JSON Graph VisualizerSee JSON as an interactive node graph with zoom, collapse and search; export PNG or SVG.KML ViewerOpen KML and KMZ files on an interactive map: placemarks, paths, polygons, folders, export.MySQL to PostgreSQL ConverterConvert MySQL dumps and CREATE TABLE statements to PostgreSQL: types, AUTO_INCREMENT, ENUMs, quotes.Text to CSV ConverterTurn space-aligned, fixed-width, pipe or tab separated text into clean CSV with a live preview.VCF File ViewerOpen vCard .vcf files as contact cards with photos, search and duplicate check, export CSV.XML ViewerBrowse XML as a collapsible tree with search, XPath of any node, attributes and big-file support.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.JSON to Python ClassGenerate Python dataclasses, Pydantic models or TypedDicts with type hints from JSON.JSON to C# ClassConvert JSON to C# classes or records with System.Text.Json or Newtonsoft attributes.JSON SorterSort JSON keys A-Z recursively, sort arrays by value or by a key, then pretty-print or minify.JSON to HTML TableConvert a JSON array of objects into clean HTML table code with CSS styles and a live preview.IPv4 to IPv6 ConverterConvert IPv4 to IPv4-mapped, 6to4 and NAT64 IPv6, extract IPv4 from IPv6, and get int/hex/binary.cURL to Code ConverterConvert curl commands to JavaScript fetch, Axios, Python requests, Node.js, PHP and Go code.Code to ImageTurn code into a beautiful syntax-highlighted PNG with themes, window frame and background.Excel to JSON ConverterConvert Excel sheets (XLSX, XLS, ODS) to JSON with header row, type and shape options.CSV to Excel ConverterConvert CSV files to a real .xlsx workbook with typed numbers and dates, one sheet per file.CSV SplitterSplit a large CSV into smaller files by row count, file count or column value, header kept.CSV MergerCombine many CSV files into one, matching columns by name, with dedupe and a source column.VCF to CSV ConverterConvert vCard (.vcf) contacts to CSV for Google or Outlook, or turn a CSV back into a VCF.Calendar Event (.ics) GeneratorCreate an .ics calendar invite with time zone, reminders and repeats + Google/Outlook links.CSV Column ExtractorPick, reorder and rename CSV columns, filter rows by value, and export a new CSV or JSON.CSV Diff CheckerCompare two CSV files by key column and see added, removed and changed rows cell by cell.CSV Duplicate Row RemoverRemove duplicate rows from a CSV by all or selected columns and download the cleaned file.CSV to HTML TableTurn CSV into clean HTML table code with a live preview, styling options and one-click copy.
See all 129 Data & File Format Converters →