Skip to content

json_utils

JSON type helper functions, operators, and a hash operator class for PostgreSQL 9.2+.

pg_json_utils · JSON type helper functions, operators, and a hash operator class for PostgreSQL 9.2+.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100611json_utilspg_json_utils0.1FUNCPostgreSQLSQL

PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18

Relationships
Requiresplpgsql

Usage

Sources:

json_utils is an early pure-SQL extension for PostgreSQL’s textual JSON type. It adds three comparison or containment-style operators and a hash operator class, but its own README warns that version 0.1 contains bugs and the implementation compares serialized text rather than JSON structure.

Core Workflow

After installation, the operators work on JSON values and character strings. The following examples illustrate their literal behavior, not semantic JSON containment.

CREATE EXTENSION json_utils;

SELECT '{"a":1}'::json = '{"a":1}'::json;
SELECT '{"a":1,"b":2}'::json ? 'a'::varchar;
SELECT '{"a":1,"b":2}'::json @> '"b":2'::varchar;

Installed Objects

  • The equality function casts both documents to character strings and compares those strings.
  • The key test searches for the exact serialized pattern consisting of a quoted key followed immediately by a colon.
  • The containment-style test performs an unrestricted substring search.
  • The hash support function derives an integer from the MD5 text of the serialized document, and the extension registers a default hash operator class for JSON.

Safety and Compatibility

These operations are lexical, so whitespace, key order, formatting, and substrings can change results without changing—or while misrepresenting—the logical JSON value. The containment-style operator can match text inside strings or nested content and should not be treated as structural containment. All helper functions are declared volatile in the cataloged SQL.

Current PostgreSQL provides structural JSONB equality, containment, existence operators, and index support. Prefer those built-in JSONB facilities for new schemas. If maintaining a legacy installation, test every predicate with adversarial formatting and duplicate or nested keys before trusting it, and check for operator conflicts in the target database before creating the extension.

The extension is relocatable, does not require superuser installation according to its control file, and declares no preload or restart requirement.

Table reader