SQL CREATE TABLE Generator · Tutorial

How to design a database table from API JSON

6 min readintermediateUpdated

You want to store records from an API in your own database. You will paste a sample response, let the tool infer the columns, and adjust keys and types for the database you use.

What you need

Steps

  1. Paste the array of records

    Load the example list of customers. If your API wraps records, such as {"data": [...]}, paste only the array inside.

  2. Review the types

    joined contains dates only, so it becomes DATE; last_login has times, so it becomes TIMESTAMPTZ in PostgreSQL. balance becomes DECIMAL(10, 2) because money must be exact.

  3. Notice nullable columns

    last_login is empty for one customer, so it has no NOT NULL. Every other column is required.

  4. Switch database

    Change Database to MySQL: timestamps become DATETIME and identifiers are quoted with backticks. Choose SQL Server and text becomes NVARCHAR.

Try it yourself

Opens the SQL CREATE TABLE Generator with this tutorial's sample loaded.

Try it now

Common mistakes

Storing money as floating point
Keep Exact DECIMAL for decimals ticked. DOUBLE can turn 0.1 + 0.2 into 0.30000000000000004.
Nested objects in one column
Nested data becomes a JSON column. If you query inside it often, move it to its own table with a foreign key instead.

Next steps

Go back to the SQL CREATE TABLE Generator, or keep going with one of these:

Tutorial · 7 min · beginner

How to create a SQL table for a CSV file

Turn a CSV export into a CREATE TABLE statement with sensible types and keys, then import the data into PostgreSQL, MySQL or SQLite.