I have a JSONB column in my database which contain nested JSON. I need to query this column but I want to preserve JSON structure and only drop unnecessary key values. Assuming this is the sample record in database:
{
"id": 1,
"foo": "bar",
"something": "anything",
"something_else": "anything_else",
"video": [
{
"id": 1,
"type": "slow",
"width": 700,
"height": 900
},
{
"id": 2,
"type": "medium",
"width": 900,
"height": 100
},
{
"id": 3,
"type": "fast",
"width": 700,
"height": 900
}
],
"image": {
"candidates": [
{
"width": 480,
"height": 600,
"scans_profile": "e35"
},
{
"width": 480,
"height": 600,
"scans_profile": "e35"
}
]
}
}
I need to get:
{
"id": 1,
"foo": "bar",
"video": [
{
"id": 1,
"width": 700,
"height": 900
},
{
"id": 2,
"width": 900,
"height": 100
},
{
"id": 3,
"width": 700,
"height": 900
}
],
"image": {
"candidates": [
{
"scans_profile": "e35"
},
{
"scans_profile": "e35"
}
]
}
}
Is there an elegant, simple way to do that? or is there any way at all?
I am using postgres 13.3