Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(MySQL) How to extract a json field with a dot inside (special character)

Tags:

json

mysql

First of all, I am using MySQL v5.7 .

Now, here is the problem... This following example works (provided by Official MySQL website) :

SELECT JSON_EXTRACT('{"id": 14, "name": "Aztalan"}', '$.name');

And it returns "Aztalan".

But this one doesn't work:

SELECT JSON_EXTRACT('{"user.id": 14, "user.name": "Aztalan"}', '$.user.name');

How can I get the "user.name" json property name with json_extract function?

like image 922
jpmottin Avatar asked Aug 11 '16 17:08

jpmottin


1 Answers

Working way is to quote the key:

SELECT JSON_EXTRACT('{"user.name": "Aztalan"}', '$."user.name"');
like image 162
Vasfed Avatar answered Oct 23 '22 23:10

Vasfed