Function inventory verified against the supplied SlopDB source checkout e5e2eb2. Entries document implemented behavior, including compatibility placeholders and restrictions.
The shared JSON family works with native JSON values and JSON document text. The JSON and JSONB conversion names use the native JSON representation. PostgreSQL adds its own builder/access/update functions; see the PostgreSQL reference.
Documents, values, and paths
Malformed documents and invalid paths fail, except JSON_VALID reports invalid document text as zero. SQL NULL and JSON null are distinct: SQL NULL usually propagates, while builders can embed it as JSON null. Ordinary SQL text is inserted as a JSON string; use JSON(text) to embed a document.
Paths start at $ and support object members, quoted member names, zero-based array indexes, last/last-N, and supported wildcards/recursive descent for reads. Modifying paths reject wildcards. Paths are bounded to 128 components. A missing path and a selected JSON null can have different results depending on the function.
-> returns JSON and ->> returns text. PostgreSQL-style #> and #>> use a textual path array such as '{a,0}'. Missing targets return SQL NULL. These operator forms are syntax over the JSON evaluator, not additional user-callable function names.
Create and inspect JSON
JSON(document)
Returns JSON
Validates and canonicalizes a JSON document. Both names use the native JSON representation; JSONB does not introduce a separate PostgreSQL binary storage engine.
SELECT JSON('{"a":1}');
Source: sql/json_functions.go · e5e2eb2
JSON_ARRAY([value, ...])
Returns JSON
Builds an array. SQL NULL becomes JSON null. JSON-typed arguments embed as JSON; ordinary text arguments become JSON strings.
SELECT JSON_ARRAY(1, 'slime', NULL);
Source: sql/json_functions.go · e5e2eb2
JSON_DEPTH(document)
Returns INTEGER
Returns maximum nesting depth, counting the root as one.
SELECT JSON_DEPTH('{"a":[1]}');
Source: sql/json_functions.go · e5e2eb2
JSON_KEYS(document [, path])
Returns JSON
Returns an array of sorted object keys. A non-object or missing target returns NULL.
SELECT JSON_KEYS('{"b":2,"a":1}');
Source: sql/json_functions.go · e5e2eb2
JSON_LENGTH(document [, path])
Returns INTEGER
Returns the number of members/elements at the root or selected path; a scalar has length one. An absent path returns NULL.
SELECT JSON_LENGTH('[1,2,3]');
Source: sql/json_functions.go · e5e2eb2
JSON_OBJECT([key, value, ...])
Returns JSON
Builds an object from key/value pairs. An odd argument count or NULL key fails. Later duplicate keys overwrite earlier ones.
SELECT JSON_OBJECT('name', 'slopdb', 'ready', 1);
Source: sql/json_functions.go · e5e2eb2
JSON_PRETTY(document)
Returns TEXT
Returns JSON indented with two spaces.
SELECT JSON_PRETTY('{"a":[1,2]}');
Source: sql/json_functions.go · e5e2eb2
JSON_QUOTE(text)
Returns TEXT
Quotes and escapes text as a JSON string. SQL NULL remains NULL.
SELECT JSON_QUOTE('slime');
Source: sql/json_functions.go · e5e2eb2
JSON_STORAGE_FREE(document)
Returns INTEGER
Validates the document and returns 0; the engine does not expose an in-place JSON free-space allocator.
SELECT JSON_STORAGE_FREE('{"a":1}');
Source: sql/json_functions.go · e5e2eb2
JSON_STORAGE_SIZE(document)
Returns INTEGER
Returns the byte length of canonical serialized JSON, not the physical on-disk LSM space used by the row.
SELECT JSON_STORAGE_SIZE('{"a":1}');
Source: sql/json_functions.go · e5e2eb2
JSON_TYPE(document)
Returns TEXT
Returns OBJECT, ARRAY, STRING, INTEGER, DOUBLE, BOOLEAN, or NULL as a text label. SQL NULL remains SQL NULL.
SELECT JSON_TYPE('[1,2]');
Source: sql/json_functions.go · e5e2eb2
JSON_UNQUOTE(value)
Returns TEXT
Decodes a quoted JSON string; other text is returned unchanged. Malformed quoted strings fail.
SELECT JSON_UNQUOTE('"slime"');
Source: sql/json_functions.go · e5e2eb2
JSON_VALID(value)
Returns INTEGER
Returns 1 for valid JSON, 0 for invalid JSON, or SQL NULL for SQL NULL.
SELECT JSON_VALID('{"a":1}');
Source: sql/json_functions.go · e5e2eb2
JSONB(document)
Returns JSON
Validates and canonicalizes a JSON document. Both names use the native JSON representation; JSONB does not introduce a separate PostgreSQL binary storage engine.
SELECT JSONB('{"a":1}');
Source: sql/json_functions.go · e5e2eb2
Read and compare JSON
JSON_CONTAINS(document, candidate [, path])
Returns INTEGER
Tests JSON containment at the root or selected path. The candidate is itself a JSON document.
Returns matching JSON or SQL NULL when no path matches. Multiple paths or wildcards produce an array of collected matches.
SELECT JSON_EXTRACT('{"a":[1,2]}', '$.a[0]');
Source: sql/json_functions.go · e5e2eb2
JSON_OVERLAPS(a, b)
Returns INTEGER
Tests for a shared array element, shared object key/value pair, or compatible scalar value.
SELECT JSON_OVERLAPS('[1,2]', '[2,3]');
Source: sql/json_functions.go · e5e2eb2
JSON_VALUE(document, path)
Returns TEXT
Returns the first matched scalar as TEXT; numbers and booleans are textual too. Missing values, JSON null, arrays, and objects return SQL NULL.
SELECT JSON_VALUE('{"a":42}', '$.a');
Source: sql/json_functions.go · e5e2eb2
Modify JSON
JSON_ARRAY_APPEND(document, path, value [, path, value, ...])
Returns JSON
Appends to the selected array, wrapping a selected scalar as an array where supported. Arguments after the document must be path/value pairs, applied in order.
Modifying paths reject wildcards. SQL text values become JSON strings unless explicitly converted to JSON.