Using MySQL JSON field to join on a table
With the help of Feras's comment and some fiddling:
SELECT
u.user_id,
u.user_name,
g.user_group_id,
g.group_name
FROM user u
LEFT JOIN user_group g on JSON_CONTAINS(u.user_groups, CAST(g.user_group_id as JSON), '$')
This appears to work, let me know if there's a better way.
Funny, I got to the opposite solution compared to Kyle's.
I wrote my query like this:
SELECT
u.user_id,
u.user_name,
g.user_group_id,
g.group_name
FROM user u
LEFT JOIN user_group g on JSON_UNQUOTE(JSON_EXTRACT(u.user_groups, '$')) = g.user_group_id;
It also works, and this solution doesn't need any transforming on the right side of the expression, this could provide a benefit in query optimizing in certain cases.