SELECT o_id, CONCAT( '{', GROUP_CONCAT( CONCAT( '"', `attribute`, '":"', `value`, '"' ) ), '}' ) json FROM t3 GROUP BY o_id