All pages
Powered by GitBook
1 of 1

Loading...

JSON_OBJECT_FILTER_KEYS

Discover JSON_OBJECT_FILTER_KEYS in MariaDB. Available from version 11.2, this function returns a new JSON object containing only the key-value pairs where the keys match those provided in a specified

JSON_OBJECT_FILTER_KEYS is available from MariaDB 11.2.

Syntax

JSON_OBJECT_FILTER_KEYS(obj, array_keys)

Description

JSON_OBJECT_FILTER_KEYS returns a JSON object with keys from the object that are also present in the array as string. It is used when one wants to get key-value pair such that the keys are common but the values may not be common.

Example

This page is licensed: CC BY-SA / Gnu FDL

SET @obj1= '{ "a": 1, "b": 2, "c": 3}';
SET @obj2= '{"b" : 10, "c": 20, "d": 30}';
SELECT JSON_OBJECT_FILTER_KEYS (@obj1, JSON_ARRAY_INTERSECT(JSON_KEYS(@obj1), JSON_KEYS(@obj2)));
+-------------------------------------------------------------------------------------------+
| JSON_OBJECT_FILTER_KEYS (@obj1, JSON_ARRAY_INTERSECT(JSON_KEYS(@obj1), JSON_KEYS(@obj2))) |
+-------------------------------------------------------------------------------------------+
| {"b": 2, "c": 3}                                                                          |
+-------------------------------------------------------------------------------------------+