JSON to SQL

Generate CREATE TABLE and INSERT statements from a JSON array. Choose your SQL dialect.

What is JSON to SQL Conversion?

JSON to SQL conversion generates the SQL statements needed to store JSON array data in a relational database. The tool reads the structure of your JSON objects, creates a CREATE TABLE statement with appropriate column types, and generates one INSERT statement per JSON object.

This is useful for seeding relational databases with data from REST APIs, importing API responses into PostgreSQL or MySQL for analysis, migrating from NoSQL (MongoDB, Firestore) to relational databases, and setting up test databases with realistic fixture data. Column types are inferred automatically from the values in your JSON.

JSON to SQL Example

Input JSON array:

json
[
  {"id": 1, "name": "Ravi", "active": true, "score": 9.5},
  {"id": 2, "name": "Priya", "active": false, "score": 8.2}
]

Generated PostgreSQL:

sql
CREATE TABLE "data" (
  "id" INTEGER,
  "name" VARCHAR(255),
  "active" BOOLEAN,
  "score" NUMERIC
);

INSERT INTO "data" ("id", "name", "active", "score") VALUES (1, 'Ravi', TRUE, 9.5);
INSERT INTO "data" ("id", "name", "active", "score") VALUES (2, 'Priya', FALSE, 8.2);

Dialect Differences

FeaturePostgreSQLMySQLSQLiteSQL Server
Identifier quoting"name"`name`"name"[name]
Boolean typeBOOLEANBOOLEANTEXTBIT (1/0)
Integer typeINTEGERINTEGERINTEGERBIGINT
Float typeNUMERICREALREALFLOAT
Long stringsTEXTTEXTTEXTTEXT
JSON columnsJSONBJSONTEXTTEXT

Common Use Cases

  • Data importConvert exported JSON from an API or NoSQL database into SQL for import into PostgreSQL or MySQL.
  • Database seedingGenerate INSERT statements from JSON fixtures to seed your development or test database.
  • Schema bootstrappingQuickly prototype a table schema from a sample JSON payload without writing SQL manually.
  • Data migrationMigrate data from a JSON-based store (MongoDB, DynamoDB) to a relational database.

Frequently Asked Questions

The converter analyzes all non-null values in each column across all rows. If all values are integers, it uses INTEGER. Floats use NUMERIC/REAL. Booleans (true/false) use BOOLEAN. Strings under 255 chars use VARCHAR(255), longer strings use TEXT. Nested objects/arrays use TEXT or JSONB depending on dialect.

All unique keys across all objects are collected as columns. Rows missing a key will have NULL inserted for that column.

Use it as a starting point. Production schemas should have PRIMARY KEY, NOT NULL, UNIQUE, and index constraints added based on your data requirements.

Yes. If you paste a single JSON object instead of an array, it is treated as a one-row table.

Related Tools