For MHS, I need to transform a table from sql to json.

It was easier than write a poem in hendecasyllabic, through the ultra pragmatic json_build_object function:

select
    json_agg(
        json_build_object(
            'device_id', device_id,
            'antibio_id', antibio_id,
            'device_antibio_id', device_antibio_id
        )
    )
from
    devices_antibio_transc;