MySQL v5.7.22 onwards you should be able to use JSON_ARRAYAGG
to select grouped attributes as a json array. Something like:
SELECT id, JSON_ARRAYAGG(JSON_OBJECT("a", t.a, "b", t.b)) as json from table t group by id;
This should return an array of json objects as second attribute in result set
| id | json |
-------------
| 1 | [{"a": "a-value-1", "b", "b-value-1"}, {"a": "a-value-2", "b": "b-value-2"}] |