Remove the wrapping of json_buid_object in postgresql

Viewed 16

This is the query of the postgresql.This returns each object wrapped with json_build_object.How to remove the wrapper of json_build_object and just return it without any wrapper in Postgresql. let sql = `SELECT json_build_object 'id',Y."Id", 'name',Y."name", 'is_enabled',Y."is_enabled", 'is_setup_complete',Y."is_setup_complete", 'approval_time',Y."approval_time", )

    "shops": [
    {
    "json_build_object": {
    "id": 1,
    "name": "Melody Garments",
    "is_enabled": true,
    "is_setup_complete": false,
    "approval_time": 10,
    "packaging_time": 30,```

1 Answers

Since it looks like your client library is already converting results to JSON, you probably don't need json_build_object at all but instead can use column aliases to control the keys.

SELECT Y."Id" as id, Y."name" as name ...

Related