JSON_CONTAINS
You are viewing an old version of this article. View
the current version here.
Syntax
JSON_CONTAINS(json_doc, val[, path])
Description
Returns whether or not the specified value is found in the given JSON document or, optionally, at the specified path within the document. Returns 1
if it does, 0
if not and NULL if any of the arguments are null. An error occurs if the document or path is not valid, or contains the *
or **
wildcards.
Examples
SET @json = '{"A": 0, "B": {"C": 1}, "D": 2}'; SELECT JSON_CONTAINS(@json, '2', '$.A'); +----------------------------------+ | JSON_CONTAINS(@json, '2', '$.A') | +----------------------------------+ | 0 | +----------------------------------+ SELECT JSON_CONTAINS(@json, '2', '$.D'); +----------------------------------+ | JSON_CONTAINS(@json, '2', '$.D') | +----------------------------------+ | 1 | +----------------------------------+ SELECT JSON_CONTAINS(@json, '{"C": 1}', '$.A'); +-----------------------------------------+ | JSON_CONTAINS(@json, '{"C": 1}', '$.A') | +-----------------------------------------+ | 0 | +-----------------------------------------+ SELECT JSON_CONTAINS(@json, '{"C": 1}', '$.B'); +-----------------------------------------+ | JSON_CONTAINS(@json, '{"C": 1}', '$.B') | +-----------------------------------------+ | 1 | +-----------------------------------------+
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.