Available in versions: Dev (3.16) | Latest (3.15) | 3.14

JSON_EXISTS predicate

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The JSON_EXISTS predicate can be used to check whether a JSON path expression produces a value within a JSON document (see also the JSON_VALUE function)

SELECT 1
FROM dual
WHERE json_exists('{"a":1}', '$.a')
create.selectOne()
      .where(jsonExists(val(JSON.valueOf("{\"a\":1}")), "$.a"))
      .fetch();

Dialect support

This example using jOOQ:

jsonExists(val(json("{\"a\":1}")), "$.a")

Translates to the following dialect specific expressions:

-- AURORA_POSTGRES, COCKROACHDB
JSON_EXISTS(CAST('{"a":1}' AS json), '$.a')

-- DB2, MARIADB, ORACLE
JSON_EXISTS('{"a":1}', '$.a')

-- MYSQL
json_contains_path('{"a":1}', 'one', '$.a')

-- POSTGRES
jsonb_path_exists(CAST('{"a":1}' AS jsonb), '$.a'::jsonpath)

-- SQLITE
json_type('{"a":1}', '$.a') IS NOT NULL

-- ACCESS, ASE, AURORA_MYSQL, BIGQUERY, DERBY, EXASOL, FIREBIRD, H2, HANA, HSQLDB, INFORMIX, MEMSQL, REDSHIFT, SNOWFLAKE, 
-- SQLDATAWAREHOUSE, SQLSERVER, SYBASE, TERADATA, VERTICA, YUGABYTE
/* UNSUPPORTED */

(These are currently generated with jOOQ 3.16, see #10141), or translate your own on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo