JSON to SQL Converter

Paste JSON and generate SQL CREATE TABLE & INSERT INTO statements

Convert JSON to SQL online and generate CREATE TABLE and INSERT INTO statements from JSON data. Paste a JSON array and get SQL scripts with columns and data types inferred automatically. This free JSON to SQL converter helps developers and data engineers import API data into MySQL, SQL Server, PostgreSQL, and other databases.

JSON Input
SQL Output

SQL output will appear here.
Press Ctrl+Enter or click Generate SQL.

About JSON to SQL Converter

The JSON to SQL Converter transforms JSON data into SQL CREATE TABLE statements with properly inferred column types. It supports MySQL, PostgreSQL, SQLite, and SQL Server dialects. Optionally generate INSERT statements to populate the table with your JSON data.

Key Features

  • Multi-dialect support — generates valid SQL for MySQL, PostgreSQL, SQLite, and SQL Server.
  • Type inference — automatically maps JSON types to appropriate SQL column types.
  • Primary key generation — optionally add an auto-increment primary key column.
  • INSERT generation — generate INSERT statements from array data to populate your table.
  • Nested flattening — nested JSON objects are flattened into columns using underscore naming.

How to Use

  1. Input JSON — paste a JSON object or array of objects into the editor.
  2. Configure — set table name, SQL dialect, and toggle options.
  3. Generate — click Generate SQL or press Ctrl+Enter.
  4. Export — copy to clipboard or download as a .sql file.

Why Convert JSON to SQL?

JSON is the default format for APIs, exports and document stores, while most business data still lives in relational databases. Moving data from one world to the other usually means writing a table definition by hand, guessing column types, and then writing INSERT statements row by row. That work is slow and easy to get wrong. This tool reads a representative JSON sample, works out a sensible schema and produces SQL you can run immediately, so you can go from an API response to a queryable table in a couple of minutes.

Real-World Use Cases

  • Loading a third-party API response into a staging table so you can explore it with ordinary SQL queries.
  • Prototyping a database schema from a sample document before writing migrations.
  • Creating seed data for development, testing and demo environments from exported JSON files.
  • Migrating a small document collection into MySQL, PostgreSQL, SQLite or SQL Server.
  • Teaching and documentation, where you need a quick example table that matches a JSON sample.

How Type Mapping Works

The converter inspects every value for a key across all objects in an array and chooses the narrowest type that fits them all. Whole numbers become integer columns, numbers with decimals become decimal or floating point columns, true and false values become boolean or bit columns, and text becomes VARCHAR or TEXT depending on the dialect. A key that is missing in some objects or contains null becomes a nullable column. Nested objects are flattened using underscore naming, so an address object with a city key becomes an address_city column.

Dialect Differences to Know About

Each database engine spells common things differently. Auto-increment keys use AUTO_INCREMENT in MySQL, SERIAL or identity columns in PostgreSQL, AUTOINCREMENT in SQLite and IDENTITY in SQL Server. Identifier quoting also differs between backticks, double quotes and square brackets. Choosing the right dialect before generating means the output can be pasted straight into your database client.

Tips for Best Results

  • Use a sample that contains several objects so optional fields and mixed types are detected correctly.
  • Review column lengths and add indexes or constraints that reflect your real data rules.
  • Arrays nested inside objects are not expanded into child tables; model those relationships separately.
  • Always test generated INSERT statements on a copy of your database before running them in production.

Frequently Asked Questions

How are JSON types mapped to SQL?

Strings map to VARCHAR/TEXT, numbers to INT/DECIMAL, booleans to BOOLEAN/BIT, null to nullable columns, and nested objects are flattened.

Can I use a JSON array?

Yes. A JSON array of objects is the ideal input. All objects are merged to determine the full column set, and INSERT statements can be generated for each row.