SQL get value from key in dictionary

Viewed 38

I have a column in my database which is called user_log. It basically logs everything a user does on the page. I use MySQL.

It looks like that:

user_id user_log
1028 { "last_login":"2022-04-08 12:03:05", "blog_entry_at":"2022-04-08 12:43:12" }

Now, I want to extract all "last_login" and get the value of it. It is a text field, but not a dict or something else

2 Answers

You can simply use JSON_VALUE() function provided that the DB is of version 8.0.21+ such as

SELECT JSON_VALUE(user_log, '$.last_login') AS extracted_value
  FROM t
Related