json_utils
pg_json_utils · JSON type helper functions, operators, and a hash operator class for PostgreSQL 9.2+.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100611 | json_utils | pg_json_utils | 0.1 | FUNC | PostgreSQL | SQL |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
- Official README at the catalog source revision
- Extension control file at the catalog source revision
- Version 0.1 extension SQL
- PGXN distribution page
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.
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.