PostgreSQL jsonb_path_match() Function

The PostgreSQL jsonb_path_match() function returns the result of executing a JSON path assertion against a specified JSON value.

jsonb_path_match() Syntax

This is the syntax of the PostgreSQL jsonb_path_match() function:

     target JSONB
   , path JSONPATH
  [, vars JSONB
  [, silent BOOLEAN]]



Required. The JSONB value to check.


Required. The JSON path assertion to perform.


Optional. The variable values used in the path.


Optional. If this parameter is provided and it is true, the function suppresses the same errors as the @? and @@ operators.

Return value

The PostgreSQL jsonb_path_match() function returns a boolean value that is the result of a JSON path assertion performed on a specified JSON value. t indicates that the specified JSON value matches the specified JSON path, and f indicates that the specified JSON value does not match the specified JSON path.

If any parameter is NULL, the jsonb_path_match() function will return NULL.

jsonb_path_match() Examples

The following example shows how to use the PostgreSQL jsonb_path_match() function to check if a JSON array contains a value greater than 1.

SELECT jsonb_path_match('[1, 2, 3]', 'exists($[*] ? (@ > 1))');

Here, we use path $[*] ? (@ > 2) to get items greater than 2 in the JSON array [1, 2, 3]. Instead, exists($[*] ? (@ > 1)) check if the JSON array contains items greater than 2. The statement is the same as jsonb_path_exists():

SELECT jsonb_path_exists('[1, 2, 3]', '$[*] ? (@ > 1)');