Add jsonb key/value pair with uuid
I managed to solve this problem using this query:
select to_jsonb(array_agg(jsonb(
                COALESCE(
                        jsonb_set(
                                imageElements,
                                '{id}',
                                to_jsonb(uuid_generate_v4()),
                                true
                            ), imageElements
                    )
            )))
from  jsonb_array_elements(
    (
        select entitiesArray-&gt;'content' -&gt; 'images' from (
                select jsonb_array_elements(column) as entitiesArray from table
        ) as column
            where entitiesArray-&gt;&gt; 'type' = 'imageGalleryModule'
    )
    ) as imageElements;