Collections:
JSON_CONTAINS_PATH() - Finding Path in JSON
How to verify if a JSON path exists in a JSON (JavaScript Object Notation) value using the JSON_CONTAINS_PATH() function?
✍: FYIcenter.com
JSON_CONTAINS_PATH(json, one_or_all, path1, path2, ...) is a MySQL built-in function that
verifies if one or all specified paths exist in a given JSON value.
For example:
SET @j = '{"a": 1, "b": 2, "c": {"d": 4}}';
SELECT JSON_CONTAINS_PATH(@j, 'one', '$.a', '$.e');
-- +---------------------------------------------+
-- | JSON_CONTAINS_PATH(@j, 'one', '$.a', '$.e') |
-- +---------------------------------------------+
-- | 1 |
-- +---------------------------------------------+
SELECT JSON_CONTAINS_PATH(@j, 'all', '$.a', '$.e');
-- +---------------------------------------------+
-- | JSON_CONTAINS_PATH(@j, 'all', '$.a', '$.e') |
-- +---------------------------------------------+
-- | 0 |
-- +---------------------------------------------+
SELECT JSON_CONTAINS_PATH(@j, 'one', '$.c.d');
-- +----------------------------------------+
-- | JSON_CONTAINS_PATH(@j, 'one', '$.c.d') |
-- +----------------------------------------+
-- | 1 |
-- +----------------------------------------+
SELECT JSON_CONTAINS_PATH(@j, 'one', '$.a.d');
-- +----------------------------------------+
-- | JSON_CONTAINS_PATH(@j, 'one', '$.a.d') |
-- +----------------------------------------+
-- | 0 |
-- +----------------------------------------+
Reference information of the JSON_CONTAINS_PATH() function:
JSON_CONTAINS_PATH(json, one_or_all, path1, path2, ...): int Verifies if one or all specified paths exist in a given JSON value. Arguments, return value and availability: json: Required. The JSON value to be searched in. one_or_all: Required. The search option: "one" or "all". path1, path2, ...: One or more JSON paths to search for. int: Return value. The verification result. Available since MySQL 5.7.
⇒ JSON_DEPTH() - Calculating Depth of JSON Value
⇐ JSON_CONTAINS() - Finding JSON in JSON
2023-12-11, 1017🔥, 0💬
Popular Posts:
What is SQL Server Transact-SQL (T-SQL)? SQL Server Transact-SQL, also called T-SQL, is an extension...
How To Query Tables and Loop through the Returning Rows in MySQL? The best way to query tables and l...
Where to find SQL Server database server tutorials? Here is a collection of tutorials, tips and FAQs...
How To Get a List of All Tables with "sys.tables" View in SQL Server? If you want to see the table y...
Where to find answers to frequently asked questions on Managing Security, Login and User in SQL Serv...