SLOPDB / DOCUMENTATION / JSON FUNCTIONS

JSON functions

Function inventory verified against the supplied SlopDB source checkout e5e2eb2. Entries document implemented behavior, including compatibility placeholders and restrictions.

← Search all SQL functions · 28 documented names/forms in this family.

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.

SELECT JSON_SET('{}', '$.items', JSON('[1,2]'));
SELECT JSON_EXTRACT('{"items":[1,2]}', '$.items[0]');

Operator forms

-> 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.

SELECT JSON_CONTAINS('[1,2]', '1');
Source: sql/json_functions.go · e5e2eb2

JSON_CONTAINS_PATH(document, one_or_all, path [, path, ...])

Returns INTEGER

Tests whether any path (one) or every path (all) exists.

SELECT JSON_CONTAINS_PATH('{"a":1}', 'one', '$.a');
Source: sql/json_functions.go · e5e2eb2

JSON_EXTRACT(document, path [, path, ...])

Returns JSON

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.

SELECT JSON_ARRAY_APPEND('{"a":[1]}', '$.a[0]', 2);
Source: sql/json_functions.go · e5e2eb2

JSON_ARRAY_INSERT(document, path, value [, path, value, ...])

Returns JSON

Inserts before a selected array index. 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.

SELECT JSON_ARRAY_INSERT('{"a":[1]}', '$.a[0]', 2);
Source: sql/json_functions.go · e5e2eb2

JSON_INSERT(document, path, value [, path, value, ...])

Returns JSON

Adds targets that are absent; existing values are kept. 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.

SELECT JSON_INSERT('{"a":[1]}', '$.a[0]', 2);
Source: sql/json_functions.go · e5e2eb2

JSON_MERGE(document, document [, document, ...])

Returns JSON

Merges objects and arrays while preserving colliding values in arrays. JSON_MERGE is an alias of JSON_MERGE_PRESERVE.

SELECT JSON_MERGE('{"a":1}', '{"a":2}');
Source: sql/json_functions.go · e5e2eb2

JSON_MERGE_PATCH(document, patch [, patch, ...])

Returns JSON

Applies merge-patch semantics. Object members with JSON null remove that key; a non-object patch replaces its target.

SELECT JSON_MERGE_PATCH('{"a":1}', '{"a":null,"b":2}');
Source: sql/json_functions.go · e5e2eb2

JSON_MERGE_PRESERVE(document, document [, document, ...])

Returns JSON

Merges objects and arrays while preserving colliding values in arrays. JSON_MERGE is an alias of JSON_MERGE_PRESERVE.

SELECT JSON_MERGE_PRESERVE('{"a":1}', '{"a":2}');
Source: sql/json_functions.go · e5e2eb2

JSON_REMOVE(document, path [, path, ...])

Returns JSON

Removes targets in sequence and returns the resulting JSON.

SELECT JSON_REMOVE('{"a":1,"b":2}', '$.a');
Source: sql/json_functions.go · e5e2eb2

JSON_REPLACE(document, path, value [, path, value, ...])

Returns JSON

Replaces existing targets; absent targets are kept absent. 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.

SELECT JSON_REPLACE('{"a":[1]}', '$.a[0]', 2);
Source: sql/json_functions.go · e5e2eb2

JSON_SET(document, path, value [, path, value, ...])

Returns JSON

Adds absent targets and replaces existing targets. 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.

SELECT JSON_SET('{"a":[1]}', '$.a[0]', 2);
Source: sql/json_functions.go · e5e2eb2
Function reference checked against engine source · e5e2eb2Edit the function reference ↗