Q: How to query JSON data from an object in sequelize? I'm new in sequelize so I'd like to ask how to query some specific data from JSON, the JSON in question is inside an onject. Suppose I have this data structure:
{ id: INTEGER, name: json, email: STRING}
{ id: 1, name : { "first": "foo", "last": "bar"}, email: blabla@gmail.com}

And want to retrieve only id and only "last" from all data like this:
{{id: 1, name: {"last": "baz"}, {id: 2, name: {"last": "doe"}}

How can I do this with sequelize guys? I'm really lost. I use postgres as database by the way. Thanks.

A: You can use attributes option with sequelize.json
const payload = await sequelize.<modelname>.findAll({
               attributes: ['id',
                           [sequelize.json('name.last'), 'last']]
    });

It means like:
select id, name->>'last' as last from ...
