Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

If I have a simple SELECT statement like this:

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

I would expect it to return Alexander , but instead it returns "Alexander". How can I get rid of the quotes? Why does this function even return the quotes too?

like image 394
Alex Avatar asked May 24 '16 01:05

Alex


People also ask

How do I remove quotation marks in MySQL?

Try this: str_replace('"', "", $string); str_replace("'", "", $string); Otherwise, go for some regex, this will work for html quotes for example: preg_replace("/<!

What is JSON extract () function in MySQL?

In MySQL, the JSON_EXTRACT() function returns data from a JSON document. The actual data returned is determined by the path you provide as an argument. You provide the JSON document as the first argument, followed by the path of the data to return.

Does MySQL 5.6 support JSON?

- Supports all the JSON types – Numbers , string, Bool , objects & arrays.

Which of the following functions create JSON values?

Two aggregate functions generating JSON values are available. JSON_ARRAYAGG() returns a result set as a single JSON array, and JSON_OBJECTAGG() returns a result set as a single JSON object.


1 Answers

You can use JSON_UNQUOTE to achieve this.

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

ref: Functions That Modify JSON Values

like image 77
Raul Avatar answered Oct 08 '22 18:10

Raul