2

I have a JSON column 'cart_data' with following data :

[{
    "type": 2,
    "amount": 500
}, {
    "type": 1,
    "amount": 600
},
, {
    "type": 1,
    "amount": 700
}]

I want to fetch cart_data column which contains type 1 and output should be :

[{
    "type": 1,
    "amount": 600
},
{
    "type": 1,
    "amount": 700
}]

Basically I want to remove objects which has type other than 1 (in this example).

Here's what I've been trying :

SELECT  order_id , 
        json_remove(json_extract(cart_data, '$[*]'),'$[0]') as cart_data 
from billing 
where json_contains(cart_data->'$[*].type', json_array(1));

In above query, 2nd parameter for json_remove is static. I want to make it dynamic to remove all objects which doesn't have type : 1

Any possibilities?

Thanks.

AkKi
  • 212
  • 2
  • 9

0 Answers0