Re: JSON_ARRAY_APPEND adding escape slash
Posted by: Peter Brawley
Date: August 22, 2022 09:47AM

So passing a JSON_OBJECT() result as a value arg in a variable to JSON_ARRAY_APPEND() adds backslashes, but passing it directly does not. Easy to conform that this so both for user vars and for declared vars in stored routines.

SET @i = JSON_ARRAY(JSON_OBJECT('a', '1', 'b', '2'));
SET @j = JSON_OBJECT('c', '3', 'd', '3');
SET @a = IF( @i IS NULL OR JSON_TYPE(@i) != 'ARRAY',
             JSON_ARRAY_APPEND( JSON_ARRAY(), '$', @j ),
             JSON_ARRAY_APPEND( @i, '$', @j )
           );
SET @b = IF( @i IS NULL OR JSON_TYPE(@i) != 'ARRAY',
             JSON_ARRAY_APPEND( JSON_ARRAY(), '$', @j ),
             JSON_ARRAY_APPEND( @i, '$', JSON_OBJECT('c', '3', 'd', '3'))
           );
SELECT @j, @a, @b\G
*************************** 1. row ***************************
@j: {"c": "3", "d": "3"}
@a: [{"a": "1", "b": "2"}, "{\"c\": \"3\", \"d\": \"3\"}"]
@b: [{"a": "1", "b": "2"}, {"c": "3", "d": "3"}]

That would seem to be a bug in JSON_ARRAY_APPEND() or its documentation. Please consider posting it to bugs.mysql.com.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: JSON_ARRAY_APPEND adding escape slash
40
August 22, 2022 09:47AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.