Skip to content

JSON to ERD — database schema diagram

Paste a database schema JSON and get an interactive ERD instantly — tables, columns, keys and foreign key relations. Runs in your browser. It earns its keep when you inherit an undocumented database, explain a join to a colleague, or check where the foreign keys point before writing a migration.

When you would reach for this diagram

  • Taking over an undocumented project and needing to know which tables exist and which ones are central.
  • Explaining how two tables relate to someone who does not write backend code, where a diagram beats ten minutes of talking.
  • Checking which foreign keys point at a table before writing a migration or deleting rows, so you do not leave orphans behind.
  • Confirming during code review whether a newly added relation is one-to-one or one-to-many.
  • Working with a production schema that must not be pasted into an unknown online tool.

Three steps to a diagram

  1. Open “How to get JSON schema”, pick your database and copy the query.
  2. Run that query on your database and copy the erd_json value.
  3. Paste it into the editor. The canvas lays it out automatically.

To see it working first, press load-sample. Ready-made queries cover PostgreSQL, MySQL and SQL Server, and any other database works if it produces the same shape.

What the diagram shows

  • Each table is a node, titled with its schema, name and table comment.
  • Each column takes one row, showing its name, type and column comment.
  • An asterisk marks the column as NOT NULL.
  • Default values appear on hover rather than inline, because they are often long enough to squeeze out the column name.
  • A PK badge marks a primary key, FK a foreign key and UQ a single-column unique constraint.
  • Edges attach to the specific columns and are labelled 1:1 or 1:N.

How 1:1 and 1:N are decided

  • A foreign key covering the child’s entire primary key is read as 1:1.
  • A foreign key that is itself a single-column unique is read as 1:1.
  • Everything else is read as 1:N.
  • One column of a composite primary key does not count as unique, so it is never read as 1:1.

Which JSON fields are required

  • Only tables[].table and columns[].name are required.
  • schema can be omitted.
  • Common aliases are accepted, for example table_name, column_name,data_type and is_nullable: "NO".
{
  "tables": [
    {
      "schema": "public",
      "table": "users",
      "comment": null,
      "columns": [
        { "name": "id", "type": "bigint", "nullable": false,
          "is_primary_key": true, "is_unique": false, "comment": null }
      ]
    }
  ],
  "relations": [
    { "constraint_name": "orders_user_id_fkey",
      "from_schema": "public", "from_table": "orders", "from_columns": ["user_id"],
      "to_schema": "public",   "to_table": "users",    "to_columns": ["id"],
      "on_delete": "CASCADE" }
  ]
}

Which objects the queries leave out

  • All three skip views, sequences, indexes and system schemas, keeping only what means something on an ERD.
  • The PostgreSQL query skips individual partitions and keeps the parent, because one partitioned table can expand into dozens of children.
  • The PostgreSQL query also skips foreign keys cloned onto partitions, or the same relation would be drawn N times.
  • FDW foreign tables are included, but they cannot have keys, so they appear as plain column lists with no relations.

Does your schema ever leave the browser

No. Parsing and layout both happen in your browser, no request carries your schema anywhere, and saves go only to localStorage. See theprivacy policy for the details.

Frequently asked questions

Can it connect to my database directly?
No, and that is deliberate. It reads JSON you exported by running a query yourself. There is no backend here and no connection feature, so no connection string or password has to be handed to anyone.
How many schemas can I save?
Up to 50, kept in this browser on this machine. They disappear if you switch computers or clear your browsing data, because there is no server to sync them to.
Are the node positions I drag around remembered?
No. A save stores the JSON text itself, and loading it runs the automatic layout again, so the diagram opens the same way every time.
Can I export the diagram as an image?
There is no export function yet, so use your operating system screenshot tool. The canvas zooms between 0.4x and 2x and pans freely, so frame what you want first.
Why do some tables have no relation lines at all?
Usually because those relationships were never declared as foreign keys in the database and are enforced by the application instead. The diagram can only draw keys that actually exist in the relations array, and FDW foreign tables show as plain column lists because they cannot have keys.