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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

JSON_EXISTS(json, path)

Parameters

ParameterDescription
json The JSON document.
path An SQL/JSON path, optionally with a filter.

Return value

boolean.

Examples

Does the path exist?
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.

With a filter
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

VersionChange
PostgreSQL 17Added

Was this page helpful?