I have below json data stored in Postgres DB with column as json:
{"users": [
{
"id": 1,
"data": [
{
"pos": "BA",
"endDate": "2022-07-31",
"startDate": "2022-01-01"
},
{
"pos": "BA2",
"endDate": "2022-09-30",
"startDate": "2022-08-01"
},
{
"pos": "BA3",
"endDate": "2023-03-31",
"startDate": "2022-10-01"
},
{
"pos": "BA4",
"endDate": "2023-06-08",
"startDate": "2023-04-01"
}
]
},
{
"id": 2,
"data": [
{
"pos": "BA",
"endDate": "2022-07-31",
"startDate": "2022-01-01"
},
{
"pos": "BA2",
"endDate": "2022-09-30",
"startDate": "2022-08-01"
},
{
"pos": "BA3",
"endDate": "2023-03-31",
"startDate": "2022-10-01"
},
{
"pos": "BA4",
"endDate": "2023-06-08",
"startDate": "2023-04-01"
}
]
},
{
"id": 3,
"data": [
{
"pos": "BA",
"endDate": "2022-07-31",
"startDate": "2022-01-01"
},
{
"pos": "BA2",
"endDate": "2022-09-30",
"startDate": "2022-08-01"
},
{
"pos": "BA3",
"endDate": "2023-03-31",
"startDate": "2022-10-01"
},
{
"pos": "BA4",
"endDate": "2023-06-08",
"startDate": "2023-04-01"
}
]
}
]
}
I need to write a query to filter the data based on the startDate and endDate. So if the startDate is 2022-01-01 and endDate is 2022-12-31 then query should return below json:
{"users": [
{
"id": 1,
"data": [
{
"pos": "BA",
"endDate": "2022-07-31",
"startDate": "2022-01-01"
},
{
"pos": "BA2",
"endDate": "2022-09-30",
"startDate": "2022-08-01"
}
]
},
{
"id": 2,
"data": [
{
"pos": "BA",
"endDate": "2022-07-31",
"startDate": "2022-01-01"
},
{
"pos": "BA2",
"endDate": "2022-09-30",
"startDate": "2022-08-01"
}
]
},
{
"id": 3,
"data": [
{
"pos": "BA",
"endDate": "2022-07-31",
"startDate": "2022-01-01"
},
{
"pos": "BA2",
"endDate": "2022-09-30",
"startDate": "2022-08-01"
}
]
}
]
}
Can someone help me with the query ?