JSON to SQL
Turn JSON arrays into SQL inserts
Convert an array of JSON objects into CREATE TABLE and INSERT statements for PostgreSQL, MySQL, SQLite or SQL Server.
- JSON
- SQL
- INSERT
- CREATE TABLE
How to use JSON to SQL
- Paste a JSON array of objects (or a single object) into Input JSON, drop a file on it, or use Open file. Try an example loads a sample.
- Choose the Dialect: PostgreSQL, MySQL, SQLite or SQL Server, and set the Table name (
schema.tableworks too). - Set Rows per INSERT, optionally pick a Primary key column, and untick Include CREATE TABLE if you only want the inserts.
- Check the inferred types in the Columns panel and any warnings, then copy the SQL, use Download .sql, or send it to another tool.
How it works
The JSON is read with the same strict parser as the JSON Formatter, which keeps numbers exactly as written. Each object is a row, and the columns are every key that appears, in the order first seen. A row without a key gets NULL there. Nested objects and arrays are not flattened; they are stored as JSON text.
Each column’s type comes from all of its values. Whole numbers become INTEGER/INT, BIGINT or an exact NUMERIC/DECIMAL depending on their range. Decimals become NUMERIC(p, s)/DECIMAL(p, s) sized to the widest value, and exponent numbers a floating-point type. Strings that are ISO dates (2024-01-15) become DATE, and date-times become TIMESTAMP, TIMESTAMPTZ when they have an offset, DATETIME, DATETIME2 or DATETIMEOFFSET, depending on the dialect. Other strings become VARCHAR(n) (16, 32, 64, 128 or 255) or TEXT, objects and arrays JSONB/JSON, and booleans BOOLEAN, BIT or INTEGER. A column with mixed kinds of values is stored as text. SQLite gets its own simpler types. Columns with a value in every row are marked NOT NULL.
Every identifier is quoted with the quote character doubled: double quotes for PostgreSQL and SQLite, backticks for MySQL and [name] for SQL Server, and every string is escaped for the chosen dialect. MySQL gets backslash escapes, SQL Server N'…' literals, and NUL characters are written as char(0) or NCHAR(0) (or removed for PostgreSQL). Numbers are written exactly as they appear in the JSON. Booleans are TRUE/FALSE, or 1/0 for SQLite and SQL Server. For MySQL, date-times with an offset are converted to UTC because DATETIME has no time zone. Conversion runs in the page as you type.
Limits
- Input is limited to about 10 MB (10 million characters); opened or dropped files to 10 MB. Only the first 1 MB of SQL is shown on screen; copy or download to get all of it.
- Rows per INSERT are capped at 10,000 for PostgreSQL and MySQL, 500 for SQLite and 1,000 for SQL Server, with a warning when your number is higher.
- Only
CREATE TABLEandINSERTare generated: no indexes, foreign keys, upserts orDROP TABLE. - The input must be an array of objects or a single object. An item that isn’t an object, such as a number or an array, is reported as an error.
- Dates are only recognised in ISO form (
YYYY-MM-DD, optionally with a time). Nested objects aren’t split into separate columns or tables. - If an object has a key twice, the last value is used. An empty key becomes a column named
column. - The MySQL output assumes the default
sql_mode. It won’t load correctly withNO_BACKSLASH_ESCAPES.
Privacy
SQL is generated entirely in your browser; your JSON is never uploaded or stored, and there is no share link. If you use Send to… to open the SQL in another tool, or receive JSON from one, it is handed over through this tab’s session storage and removed as soon as the receiving tool reads it.
Frequently asked questions
Is the generated SQL safe from injection?
Every value is turned into a literal by the tool rather than pasted in. Identifiers are always quoted with the quote character doubled, strings are escaped for the chosen dialect, and numbers are only ever valid JSON number text. Hostile keys, table names and values stay inside their literals.
How are nested objects and arrays stored?
As JSON text in a single column, typed JSONB in PostgreSQL, JSON in MySQL, TEXT in SQLite and NVARCHAR(MAX) in SQL Server. They are not flattened into extra columns.
Why is a column TEXT instead of a number?
The column holds more than one kind of value, for example numbers in some rows and strings in others, so it’s stored as text to keep every value. Values that are null or missing don’t count. They only make the column nullable.
Are big numbers and decimals kept exactly?
Yes. Numbers are written exactly as in the JSON, so long IDs and amounts like 120.50 aren’t rounded. Integers beyond 64 bits get an exact NUMERIC/DECIMAL type where the dialect allows it.
What does the Primary key option check?
The chosen column is marked PRIMARY KEY in the CREATE TABLE. You get a warning if it’s missing or null in some rows or has duplicate values. For text keys, SQL Server and MySQL get a bounded type such as NVARCHAR(450) or VARCHAR(768) so the key can be indexed.
More tools
- Clean Image: Inspect and remove hidden image metadata
- JWT Decoder: Decode and verify JSON Web Tokens
- Diff Checker: Compare two texts line by line
- JS Runner: Run JavaScript and TypeScript in your browser
- JSON Formatter: Format, validate and minify JSON
- Encode / Decode: Base64, URL, HTML entity and hex
- Hash Generator: MD5, SHA and HMAC of any text
- UUID Generator: Generate UUID v4 and v7 in bulk
- Timestamp Converter: Unix time ↔ human dates
- Regex Tester: Test regular expressions live
- URL Parser: Break a URL into its parts
- HTTP Status Codes: Look up any HTTP status code
- MIME Type Lookup: File extension ↔ MIME type
- Password Generator: Strong random passwords and passphrases
- Random String Generator: Random tokens, IDs and keys
- Slug Generator: Turn titles into URL slugs
- Case Converter: camelCase, snake_case, Title Case and more
- Word Counter: Count words, characters and reading time
- JSON to TypeScript: Generate TypeScript types from JSON
- JSON Diff: Compare two JSON documents structurally
- YAML ↔ JSON: Convert between YAML and JSON
- XML ↔ JSON: Convert between XML and JSON
- CSV ↔ JSON: Convert between CSV and JSON
- CSV Viewer: View, sort and filter CSV files
- SQL Formatter: Format and beautify SQL queries
- cURL ↔ Fetch: Convert cURL commands to fetch and back
- Markdown Editor: Write Markdown with a live preview
- Text Cleaner: Remove duplicate lines, empty lines and extra spaces
- Find & Replace: Find and replace in any text
- Cron Expression Builder: Build and explain cron schedules
- User-Agent Parser: Identify browser, OS and device from a user agent
- HTTP Headers Inspector: Paste response headers and get them explained
- JWT Generator: Create and sign test JSON Web Tokens
- Certificate Inspector: Decode PEM certificates and keys
- Meta Tag Inspector: Check a page's SEO and social tags
- UTM Builder: Build campaign URLs with UTM parameters
- URL Cleaner: Strip tracking parameters from links
- Robots.txt Generator: Create and test a robots.txt file
- Sitemap Generator: Create an XML sitemap from a list of URLs
- Image Compressor: Shrink JPEG, WebP and AVIF images in your browser
- Image Resizer: Resize images by pixels, percentage or to fit a box
- Image Converter: Convert between PNG, JPEG, WebP and AVIF
- Image to Base64: Encode images as Base64 data URIs and decode them back
- SVG Optimizer: Minify and sanitize SVG files
- Favicon Generator: Make favicon.ico, Apple and Android icons from an image or emoji
- Color Converter: HEX, RGB, HSL, OKLCH and contrast checks
- Number Base Converter: Binary, octal, decimal, hex and float bits
- IP / CIDR Calculator: Subnets, masks and IP ranges for IPv4 and IPv6
- JSONPath Query: Query JSON with JSONPath expressions
- JSON Schema Validator: Validate JSON against a schema, or generate one
- Semver Checker: Check versions against semver ranges
- chmod Calculator: Unix permissions: rwx ↔ octal
- .env Diff: Compare and validate .env files
- TOTP Generator: Generate and verify 2FA codes
- String Escaper: Escape and unescape strings for any language
- Unicode Inspector: See every character, code point and hidden symbol
- Mock Data Generator: Generate realistic fake data
- QR Code Generator: Create QR codes for links, Wi-Fi and contacts
- Lorem Ipsum Generator: Placeholder text in paragraphs, sentences or words
- Date Calculator: Date differences, business days and durations
- Unit Converter: Convert bytes, lengths, weights, temperatures and more
- Query CSV with SQL: Run SQL queries on CSV files
- PDF Merge & Split: Merge, split, reorder and rotate PDFs
- PDF Metadata Cleaner: See and remove hidden PDF metadata
- Office Metadata Cleaner: Remove author and revision data from Word, Excel and PowerPoint
- Images to PDF: Combine images into one PDF
- Image Editor: Crop, rotate, resize and adjust images
- Encrypt / Decrypt Text: Encrypt text with a passphrase (AES-GCM)
- SSH Key Generator: Generate Ed25519 and RSA SSH keys locally
- Email Header Analyzer: Trace an email's path and check SPF, DKIM and DMARC
- JSON to Code: Generate Go, Python, Rust, Java, C# and Kotlin models from JSON
- docker run ↔ Compose: Convert docker run commands to docker-compose and back
- Color Palette Extractor: Pull the dominant colours out of any image
- Password Strength Checker: How long would your password take to crack?
- SPF / DKIM / DMARC Checker: Validate and explain email DNS records
- Kubernetes YAML Checker: Validate and explain Kubernetes manifests
- .gitignore Generator: Build a .gitignore from presets
- CSP Builder: Build and check a Content-Security-Policy
- JSON-LD Generator: Create schema.org structured data
- Open Graph Image Generator: Make 1200×630 social preview images
- CSS Generator: Gradients, shadows, clamp() and more
- Time Zone Meeting Planner: Find meeting times across time zones