I have a Postgres JSON column (column name = data), in which I wanted to delete all the attributes inside the JSON object.
JSON
{
"headerText": "header_text",
"vendor": {
"id": "some text",
"metadata": 123123,
"startDate": "1234234",
"assetIds": [
"some text"
],
"endDate": "234435",
"publishStart": 12443245,
"publishEnd": 978128123
},
"footerText": "some_text"
}
So, here the attributes inside the vendor json object are dynamic, which means there may be additional attributes.
So I tried the below queries, but was unable to yield the expected result
1. update table_name set data = data::jsonb #- '{vendor.*}'
2. update table_name set data = data::jsonb - '{vendor.*}'::text[]
Expected:
{
"headerText": "header text",
"vendor": {},
"footerText": "some text"
}