JSON → PostgreSQL

JSON input
Loading editor...
PostgreSQL outputLive
Loading editor...
// Generated PostgreSQL code will appear here...

What is JSON → PostgreSQL?

Convert JSON to PostgreSQL tables in one step. Paste a JSON object or an array of objects and get ready-to-run CREATE TABLE statements, with column types inferred from your data, NOT NULL where every record has a value, and a primary key.

Nested objects and arrays of objects become child tables linked with foreign keys (one-to-one or one-to-many), so the schema is properly normalized. If you prefer to keep nested data together, switch the setting to store it in JSON columns instead.

PostgreSQL types are used where they fit: JSONB for free-form data, native arrays such as TEXT[] for lists of values, TIMESTAMPTZ for ISO timestamps with a zone, UUID for UUID strings, and identity columns for generated keys. Indexes are added on one-to-many foreign keys, which PostgreSQL does not create automatically.

Turn on INSERT statements to load the JSON data itself. Child rows get generated ids that link them to their parent, and values are escaped correctly for PostgreSQL. Everything runs in your browser, so your data never leaves your machine.

Features

  • CREATE TABLE statements in PostgreSQL syntax
  • Column types inferred from values: integers, decimals, booleans, text, dates, timestamps and UUIDs
  • NOT NULL for fields present in every record
  • Reuses a unique id field as the primary key, or adds an auto-increment key
  • Nested objects and arrays become child tables with foreign keys, or JSON columns
  • Optional INSERT statements with correct escaping
  • Reserved words such as user and order are quoted automatically
  • 100% client-side: nothing is uploaded

How to use JSON → PostgreSQL

  1. Paste your JSON. Enter a JSON object or an array of objects. Each object becomes a row.
  2. Set the options. Open Settings to name the root table, choose child tables or JSON columns for nested data, and add INSERT statements or IF NOT EXISTS.
  3. Review the schema. Check the generated types and keys, and adjust names or lengths if your real data needs more room.
  4. Copy or download. Copy the SQL or download it as a .sql file and run it in PostgreSQL.

Examples

Nested JSON to related tables

The root table is named users in Settings. address becomes a one-to-one child table, orders a one-to-many child table.

Input

[
  {
    "id": 1,
    "name": "Ada",
    "email": "ada@example.com",
    "signedUpAt": "2026-01-02T10:00:00Z",
    "address": {
      "city": "London"
    },
    "orders": [
      {
        "sku": "A1",
        "qty": 2
      }
    ]
  }
]

Output

-- PostgreSQL schema generated by JSON PowerHouse

CREATE TABLE IF NOT EXISTS users (
    id INTEGER NOT NULL PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT NOT NULL,
    signed_up_at TIMESTAMPTZ NOT NULL
);

CREATE TABLE IF NOT EXISTS address (
    id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    user_id INTEGER NOT NULL UNIQUE,
    city TEXT NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS orders (
    id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    user_id INTEGER NOT NULL,
    sku TEXT NOT NULL,
    qty INTEGER NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_orders_user_id ON orders (user_id);

JSON array to INSERT statements

With INSERT statements turned on, each object becomes a row and quotes are escaped.

Input

[
  {
    "id": 1,
    "name": "Ada",
    "active": true
  },
  {
    "id": 2,
    "name": "O'Brien",
    "active": false
  }
]

Output

-- PostgreSQL schema generated by JSON PowerHouse

CREATE TABLE IF NOT EXISTS users (
    id INTEGER NOT NULL PRIMARY KEY,
    name TEXT NOT NULL,
    active BOOLEAN NOT NULL
);

INSERT INTO users (id, name, active) VALUES
    (1, 'Ada', TRUE),
    (2, 'O''Brien', FALSE);

Frequently asked questions

How do I convert JSON to a PostgreSQL table?

Paste your JSON into the input editor. The tool reads every record, works out a PostgreSQL type for each field, and writes a CREATE TABLE statement you can run directly. Turn on INSERT statements to load the data too.

Which PostgreSQL types does it use?

INTEGER or BIGINT for whole numbers, DOUBLE PRECISION for decimals, BOOLEAN, TEXT, DATE, TIMESTAMP or TIMESTAMPTZ, UUID, JSONB for mixed or nested data, and arrays like TEXT[] or INTEGER[] for lists of values. Generated keys use BIGINT GENERATED BY DEFAULT AS IDENTITY.

How are nested objects and arrays handled?

By default each nested object becomes a child table with a UNIQUE foreign key (one-to-one), and each array of objects becomes a child table with a foreign key (one-to-many). Arrays of plain values become array or JSON columns. You can switch to storing all nested data in JSON columns instead.

Which column becomes the primary key?

If every record has a unique, non-null id field, it is used as the primary key. Otherwise an auto-increment id column is added.

Why is a column NOT NULL?

A column is NOT NULL when every record in your sample has a non-null value for it. Paste more varied sample data if some fields can be missing in practice.

Is my data uploaded?

No. The schema and INSERT statements are generated entirely in your browser.