Our company sells subscriptions. On renewal we want to get the subscription data, remove the discount rateplancharge, and maintain the entire data structure for other downstream processes. Here is my JSON :
{
"order": {
"Id": "1234",
"Subscription": {
"Id": "567",
"AccountId": "890",
"rateplans": [
{
"Id": "abc",
"Name": "Rate Plan 1",
"rateplancharges": [
{
"Id": "def",
"Name": "Savings Plan Plus"
},
{
"Id": "ghi",
"Name": "Savings Plan Discount"
}
]
},
{
"Id": "jkl",
"Name": "Rate Plan 2",
"rateplancharges": [
{
"Id": "def",
"Name": "Savings Plan Plus"
}
]
}
]
}
}
}
I am looking for a result like :
{
"order": {
"Id": "1234",
"Subscription": {
"Id": "567",
"AccountId": "890",
"rateplans": [
{
"Id": "abc",
"Name": "Rate Plan 1",
"rateplancharges": [
{
"Id": "def",
"Name": "Savings Plan Plus"
}
]
},
{
"Id": "jkl",
"Name": "Rate Plan 2",
"rateplancharges": [
{
"Id": "def",
"Name": "Savings Plan Plus"
}
]
}
]
}
}
}
I can get the rateplancharges I want with (order.Subscription.rateplans.rateplancharges[Id="def"]), but that doesn't maintain the rateplan structure and loses the Order details and hierarchy.
Any ideas how to do this?
$ ~> | $.order.Subscription.rateplans | { "rateplancharges": $.rateplancharges[Id != "ghi"][] }|