How can I use JSON_EXTRACT in MySQL and get a string without quotes?

If I have a simple SELECT statement:

SELECT JSON_EXTRACT('{"username":"Alexander"}', '$.username'); 

I expect him to return Alexander , but instead return "Alexander" . "Alexander" How can I get rid of quotes? Why does this function even return quotes?

+12
mysql
source share
3 answers

you can use replace () with it to remove quotes

 SELECT replace(JSON_EXTRACT('{"username":"Alexander"}', '$.username'), '\"', ''); 
-2
source share

You can use JSON_UNQUOTE to achieve this.

 select JSON_UNQUOTE(JSON_EXTRACT(base, '$.scope')) as scope from t_name 

link:

+15
source share

You can use SUBSTRING

 SELECT SUBSTRING( JSON_EXTRACT ( '{"username":"Alexander"}', '$.username' ), 2, ( LENGTH( JSON_EXTRACT ( '{"username":"Alexander"}', '$.username' ) ) - 2 ) ); 
0
source share

All Articles