select json_object(
'name', l1.Name,
'children', JSON_ARRAYAGG(json_object('name', l2.Name, 'children', l2.children))
) as json
from infrastructures l1
left join (
select l2.name
, l2.id_infrastructure
, JSON_ARRAYAGG(json_object('name', l3.name)) as children
from zones l2
left join locals l3 on l3.id_zone = l2.id
group by l2.id
) l2 on l2.id_infrastructure = l1.id
group by id