PostgreSQL 18 reference · JSON Functions
PostgreSQL JSON_EXISTS() Function
Return true if an SQL/JSON path finds anything in a JSON document. Added in PostgreSQL 17.
PostgreSQL 18 Since 17
Syntax
JSON_EXISTS(json, path)
Parameters
| Parameter | Description |
|---|---|
json |
The JSON document. |
path |
An SQL/JSON path, optionally with a filter. |
Return value
boolean.
Examples
SELECT JSON_EXISTS('{"a":{"b":1}}', '$.a.b') AS has_b, JSON_EXISTS('{"a":{}}', '$.a.b') AS missing;
Output
has_b | missing -------+--------- t | f (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT JSON_EXISTS('{"items":[{"p":3},{"p":12}]}', '$.items[*] ? (@.p > 10)') AS expensive_item;
Output
expensive_item ---------------- t (1 row)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 17 | Added |
Related
JSON_VALUE()· Extract one scalar from JSON with an SQL/JSON path and return it as a chosen SQL type. Added in PostgreSQL 17.@> and ?· Test JSON containment with @> (left contains right) and key existence with ?, both of which a GIN index can speed up.- SQL String Functions · tutorial