This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-15. For the latest, interactive version please visit https://mariadb.com/kb/.

Need delete same values in a json

SET @json1 = '{"ccmilestones":"10701", "descriptions":"10701,10702"}'; SET @json2 = '{"ccmilestones":"10701", "descriptions":"10702,10703", "lolo": "lolita"}'; SELECT JSON_MERGE_PRESERVE(@json1,@json2);

RESULT = ["{"code": ["10701", "10701"], "descriptions": ["10701,10702", "10702,10703"], "lolo": "lolita"}"]

I NEED THIS = ["{"code": ["10701"], "descriptions": ["10701, "10702,10703"], "lolo": "lolita"}"]

The values in ache key value array will be unique.

Answer Answered by Ian Gilfillan in this comment.

JSON_MERGE_PATCH does not preserve members with duplicate keys. It doesn't give you quite what you said you wanted, but may be helpful for what you're trying to achieve:

SELECT JSON_MERGE_PATCH(@json1,@json2);
+----------------------------------------------------------------------------+
| JSON_MERGE_PATCH(@json1,@json2)                                            |
+----------------------------------------------------------------------------+
| {"ccmilestones": "10701", "descriptions": "10702,10703", "lolo": "lolita"} |
+----------------------------------------------------------------------------+
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.