Schema Converter · template

SQL DDL to JSON Schema

Turn a Postgres CREATE TABLE statement into a JSON Schema from your AI assistant.

You have a Postgres table. You need a JSON Schema for the same record. Use this when an API or a test must check rows as JSON. The output keeps the column names, the descriptions and the CHECK values, and marks the NOT NULL columns as required. The page shows the recorded output and lists what did not carry over.

What you get

A JSON Schema with seven properties. Six are required and status keeps its four allowed values. This is the answer CoreModels gave on 3 December 2026 for the file below.

order.schema.json

{
  "type": "object",
  "properties": {
    "order_id": {
      "type": "string",
      "description": "Order number printed on the receipt."
    },
    "customer_id": {
      "type": "string",
      "description": "The customer who placed the order."
    },
    "status": {
      "enum": [
        "placed",
        "shipped",
        "delivered",
        "returned"
      ],
      "description": "Where the order is now."
    },
    "total_amount": {
      "type": "number",
      "description": "Order total, tax included."
    },
    "currency": {
      "type": "string",
      "description": "ISO 4217 currency code."
    },
    "placed_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the customer placed the order."
    },
    "discount_code": {
      "type": "string",
      "description": "Code used at checkout, if any."
    }
  },
  "required": [
    "order_id",
    "customer_id",
    "status",
    "total_amount",
    "currency",
    "placed_at"
  ],
  "title": "orders",
  "description": "A purchase order placed by a customer."
}

What you need

  • A CoreModels account with one project. Every plan starts with a 14-day free trial; a card is required to start.
  • The tool uses the project only to check your access. It writes nothing.
  • An assistant that speaks MCP, such as Claude Code, Claude Desktop or Cursor.
  • A PostgreSQL DDL file.

Run it

1. Connect your assistant

In Claude Code, run this command. Then sign in when it asks.

claude mcp add --transport http coremodels https://go.coremodels.io/mcp

Cursor, Claude Desktop and other clients: connect guide.

2. Save the file as order.sql

Use your own file, or start with this one.

order.sql

-- Flat shop order (PostgreSQL)

CREATE TABLE orders (
  order_id       text           NOT NULL,
  customer_id    text           NOT NULL,
  status         text           NOT NULL,
  total_amount   numeric(12, 2) NOT NULL,
  currency       text           NOT NULL,
  placed_at      timestamptz    NOT NULL,
  discount_code  text,
  CONSTRAINT orders_pkey PRIMARY KEY (order_id),
  CONSTRAINT orders_status_chk
    CHECK (status IN ('placed', 'shipped', 'delivered', 'returned'))
);

COMMENT ON TABLE  orders IS 'A purchase order placed by a customer.';
COMMENT ON COLUMN orders.order_id IS 'Order number printed on the receipt.';
COMMENT ON COLUMN orders.customer_id IS 'The customer who placed the order.';
COMMENT ON COLUMN orders.status IS 'Where the order is now.';
COMMENT ON COLUMN orders.total_amount IS 'Order total, tax included.';
COMMENT ON COLUMN orders.currency IS 'ISO 4217 currency code.';
COMMENT ON COLUMN orders.placed_at IS 'When the customer placed the order.';
COMMENT ON COLUMN orders.discount_code IS 'Code used at checkout, if any.';

3. Ask for the conversion

Use the CoreModels transform_schema tool to convert order.sql from sql to jsonschema. Pass the whole file as sourceSchema. Use any project from list_projects. Save the result as order.schema.json, then list every entry in lossiness.

Your assistant calls transform_schema with these arguments.

transform_schema

{
  "graphProjectId": "<your project id>",
  "sourceFormat": "sql",
  "sourceSchema": "<contents of order.sql>",
  "targetFormat": "jsonschema"
}

What did not carry over

  • We tested one table. Several tables with foreign keys are not tested on this page.

CoreModels reported these changes with the answer:

  • Element[ordersOrderId]: JSON Schema has no primary key; that 'order_id' is in the primary key was dropped.
  • Element[ordersTotalAmount]: JSON Schema cannot hold decimal(12,2); it became the nearest type.

We compared the two files ourselves and also found:

  • The empty value. discount_code can be null in the input. In the output you can leave it out, but null is not valid.
  • Extra fields. The output does not forbid fields that are not in the list.

Compare your own files too. A different file can lose other things.

Check it yourself

Validate the file against its own JSON Schema dialect.

pip install check-jsonschema
check-jsonschema --check-metaschema order.schema.json

Same file, other formats

← Back to Schema Converter

Start building

14-day free trial. Builder $49/mo after the trial. Cancel any time.