/*
{
"first_name": "Jared",
"concatDeails":{ "conctant_name": "Jared Ely"},
"Payments":[{"payment_id": 1,"amount":100 , "credit": null }]
}
*/
create table customer (id int, first_name varchar, last_name varchar);
insert into customer values (1, 'Jared', 'Ely');
create table payment (payment_id int, customer_id int, amount int, credit int);
insert into payment values (1, 1, 100, null), (2, 1, 50, 50);
create table address (customer_id int, city varchar, Zip varchar);
insert into address values (1, 'NY', '123123');
select json_build_object('first_name' , customer.first_name ,'concatDeails' ,json_build_object('last_nam1e' , customer.last_name||customer.last_name),
(select json_build_object('address' ,jsonb_build_array('city_id' , address.city, 'postal_code' ,address.zip) )
from address where address.customer_id=customer.id )
)
from customer;