All rules

Schema

postgresql/consistent-jsonb-over-json

Enforce a consistent stance on `jsonb` vs `json` for column types.

  • Type suggestion
  • Recommended warn
  • Fixable no

Why this matters

`jsonb` stores a parsed representation, supports GIN indexes, and is what application code almost always wants. `json` is only the right choice if you specifically need byte-exact round-tripping of input text. Pick one direction with the `style` option.

Examples

Incorrect

Incorrect
CREATE TABLE events (payload JSON);

Correct

Correct
CREATE TABLE events (payload JSONB);

Configure it

// eslint.config.js
import postgresql from "eslint-plugin-postgresql";

export default [
  {
    files: ["**/*.sql"],
    languageOptions: {
      parser: postgresql.configs.recommended.languageOptions.parser,
    },
    plugins: { postgresql },
    rules: {
      "postgresql/consistent-jsonb-over-json": [
        "warn",
        {
          style: "always",
        },
      ],
    },
  },
];

Options

style "always" | "never" default: "always"
`always` (default) requires `jsonb` over `json`. `never` requires `json` over `jsonb` for projects that rely on `json`'s preservation of key order, whitespace, and duplicate keys.
Try this rule

Edit the SQL — only consistent-jsonb-over-json is enabled.

Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.

0 errors 0 warnings parse 0ms · rules 0ms
Diagnostics

No issues found.

2 rules enabled.

Rule under test consistent-jsonb-over-json — plus no-syntax-error as a safety net.
eslint-plugin-postgresql

An ESLint plugin that lints .sql files with real PostgreSQL grammar and a curated set of best-practice rules.

© 2026 eslint-plugin-postgresql contributors Built on libpg-query · PostgreSQL 17