Home › Developer Tools › JSON to SQL Converter

JSON to SQL Converter

Paste a JSON array of objects and get a CREATE TABLE statement with inferred column types plus INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server. Nested objects can be stored as JSON columns or flattened into separate columns.

Last updated:

Converts automatically as you type. Nothing is uploaded.
Detected columns
#ColumnSQL typeNulls / missingExample
Advertisement
Advertisement

How to use the JSON to SQL Converter

  1. Paste your JSON (an array of objects), upload a .json file, or click Sample.
  2. Choose the SQL dialect and type the table name.
  3. Decide how to handle nested data: keep it as a JSON column or flatten it into separate columns.
  4. Set the options: rows per INSERT, CREATE/DROP TABLE, primary key, NOT NULL and transaction.
  5. Copy or download the .sql file and run it in your database client.

Type mapping by dialect

JSON values in the columnMySQLPostgreSQLSQLiteSQL Server
Whole numbers (42)INTINTEGERINTEGERINT
Whole numbers above 2,147,483,647BIGINTBIGINTINTEGERBIGINT
Decimals (1250.5)DECIMAL(p,s)NUMERIC(p,s)REALDECIMAL(p,s)
true / falseBOOLEANBOOLEANINTEGER (1/0)BIT (1/0)
"2024-01-15"DATEDATETEXTDATE
"2024-01-15T09:30:00"DATETIMETIMESTAMPTEXTDATETIME2
"2024-01-15T09:30:00Z"VARCHAR(35)TIMESTAMPTZTEXTDATETIMEOFFSET
Strings up to 255 charactersVARCHAR(n)VARCHAR(n)TEXTNVARCHAR(n)
Longer stringsTEXTTEXTTEXTNVARCHAR(MAX)
Objects and arraysJSONJSONBTEXTNVARCHAR(MAX)

A column containing values of different JSON types (for example numbers in some rows and strings in others) falls back to VARCHAR or TEXT so every value fits. null and missing keys always become SQL NULL. VARCHAR lengths are rounded up to 10, 20, 50, 100, 150 or 255 characters to leave a little room for longer values later.

Example

The JSON [{"id":1,"name":"Ann","tags":["a"]},{"id":2,"name":"O'Brien"}] with the PostgreSQL dialect produces:

CREATE TABLE "users" (
  "id" INTEGER NOT NULL,
  "name" VARCHAR(10),
  "tags" JSONB,
  PRIMARY KEY ("id")
);

INSERT INTO "users" ("id", "name", "tags") VALUES
  (1, 'Ann', '["a"]'),
  (2, 'O''Brien', NULL);

JSON column or flattened columns?

  • JSON column keeps the original structure and suits data you mostly read back as a whole. PostgreSQL JSONB and MySQL JSON can still be queried with operators such as ->> and JSON_EXTRACT().
  • Flatten turns nested objects into ordinary columns (address_city, address_zip), which is easier to index, filter and join. Arrays are still stored as JSON text because they can hold any number of items; for real one-to-many data, move them to a separate table.
  • For millions of records, a bulk loader is faster than INSERT statements: PostgreSQL can load JSON lines with COPY, MySQL with LOAD DATA, and SQL Server can read JSON directly with OPENJSON.

Frequently asked questions

What JSON structure does the converter expect?

An array of objects, where each object is one row and each key is a column, for example [{"id":1,"name":"Ann"},{"id":2,"name":"Bo"}]. A single object becomes one row, and if the array sits inside a wrapper object such as {"data":[...]} or {"results":[...]}, the first array of objects is used automatically.

How are column types chosen?

Each column's values are inspected across all rows. Whole numbers become INT, or BIGINT above 2,147,483,647; numbers with decimals become DECIMAL(p,s) sized to fit; true/false becomes BOOLEAN (BIT in SQL Server, INTEGER in SQLite); strings shaped like YYYY-MM-DD or a date-time become DATE or DATETIME/TIMESTAMP; other strings become VARCHAR sized to the longest value, or TEXT if longer than 255 characters.

What happens to nested objects and arrays?

By default they are stored as JSON text in a JSON-typed column: JSON in MySQL, JSONB in PostgreSQL, NVARCHAR(MAX) in SQL Server and TEXT in SQLite. Choose Flatten to turn {"address":{"city":"Oslo"}} into a column named address_city instead; arrays are still stored as JSON.

What if objects have different keys?

The converter collects the union of all keys in the order they first appear. When an object lacks a key, NULL is inserted for that column.

How are quotes and special characters escaped?

Strings are wrapped in single quotes with embedded single quotes doubled ('O''Brien'), which is standard SQL. MySQL output also escapes backslashes, and SQL Server strings use the N'...' prefix to preserve Unicode.

Are very large numbers kept exactly?

JSON numbers are read as JavaScript double-precision values, which are exact up to 9,007,199,254,740,991. Larger integers, such as some 64-bit IDs, should be stored as strings in your JSON to keep every digit.

Is my JSON sent to a server?

No. Parsing and SQL generation run entirely in your browser, so your data never leaves your device.

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

SQL to JSON ConverterConvert SQL INSERT statements and dumps into a JSON array of row objects, with CSV export.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.MongoDB Query TesterTest MongoDB find filters, projections and aggregation pipelines on sample JSON documents.MySQL to PostgreSQL ConverterConvert MySQL dumps and CREATE TABLE statements to PostgreSQL: types, AUTO_INCREMENT, ENUMs, quotes.SQL Dialect ConverterTranslate SQL between MySQL, PostgreSQL, SQLite, SQL Server, Oracle, BigQuery and more.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.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.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.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.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.File to Base64Convert any file to a Base64 string or data URI with MIME detection, line wrap and download.HTML Table to CSVExtract any table from HTML or page source to CSV, TSV or JSON, with colspan and rowspan handled.IEEE 754 Floating Point ConverterConvert decimals to 32/64-bit IEEE 754 floats: toggle bits, see hex, exact value and rounding error.
See all 129 Data & File Format Converters →