json Request:
INSERT INTO test.demotbl (data)
VALUES ('{
"x1": "Americas",
"x2": "West",
"x3": [{
"x_id": "sam"
}],
"x4": {
"a1": true,
"a2": false,
"a3": [
"xx",
"xx"
],
"a4": [
"Josh"
],
"y1": [{
"id": "RW",
"z2": true,
"z3": "USER",
"z4": [{
"name": "john"
}]
},
{
"id": "RO",
"z2": false,
"z3": "SELECT",
"z4": [{
"name": "salin"
}
{
"id": "DBA",
"z2": false,
"z3": "SELECT",
"z4": [{
"name": "Samule"
}]
}
]
}
}'::jsonb)
Question 1 :how can i delete the the array values where "id":"RO" from y1 array ? There can be any no of element in the y1 json array i want to delete the array value based on id condition.
how can i delete the the array values where "id":"RO" from y1 array ? There can be any no of element in the y1 json array i want to delete the array value based on id condition.
Expected Output after deleting:
{
"x1": "Americas",
"x2": "West",
"x3": [{
"x_id": "sam"
}],
"x4": {
"a1": true,
"a2": false,
"a3": [
"xx",
"xx"
],
"a4": [
"Josh"
],
"y1": [{
"id": "RW",
"z2": true,
"z3": "USER",
"z4": [{
"name": "john"
}]
},
{
"id": "DBA",
"z2": false,
"z3": "SELECT",
"z4": [{
"name": "Samule"
}]
}
]
}
}
Question 2 : How can i only delete the "id":"RO" from the y1 array
Expected Output:
{
"x1": "Americas",
"x2": "West",
"x3": [{
"x_id": "sam"
}],
"x4": {
"a1": true,
"a2": false,
"a3": [
"xx",
"xx"
],
"a4": [
"Josh"
],
"y1": [{
"id": "RW",
"z2": true,
"z3": "USER",
"z4": [{
"name": "john"
}]
},
{
"z2": false,
"z3": "SELECT",
"z4": [{
"name": "salin"
}
{
"id": "DBA",
"z2": false,
"z3": "SELECT",
"z4": [{
"name": "Samule"
}]
}
]
}
}