I have to make a JOLT filter to delete a field based on condition, also the filter has to work with two different JSON structures.
So, here is the case.
I have these JSONs:
JSON 1:
{
"header": {
"key": "value"
},
"payload": {
"someArray": [
{
"key1": "val1"
}
],
"elements": [
{
"service": "serviceOne",
"something": "somethingValue"
},
{
"service": "THIS_SERVICE",
"attributes": [
{
"something": "somethingValue",
"attributes_here": {
"key1": "val1",
"key2": "val2",
"key3": "val3",
"key4": "val4",
"key5": "val5",
"key6": "val6"
}
}
]
}
]
},
"data": {
"key1": "val1"
}
}
JSON 2:
{
"responseMessage": {
"header": {
"key": "value"
},
"payload": {
"someArray": [
{
"key1": "val1"
}
],
"elements": [
{
"service": "serviceOne",
"something": "somethingValue"
},
{
"service": "THIS_SERVICE",
"attributes": [
{
"something": "somethingValue",
"attributes_here": {
"key1": "val1",
"key2": "val2",
"key3": "val3",
"key4": "val4",
"key5": "val5",
"key6": "val6"
}
}
]
}
]
},
"data": {
"key1": "val1"
},
"state": {
"state1": "state1"
}
},
"status": [],
"notes": []
}
I need the filter to remove for example key2
and key5
from the attributes_here
only if the service
value is THIS_SERVICE
and keep the same structure for the JSON.
Desired output:
JSON 1:
{
"header": {
"key": "value"
},
"payload": {
"someArray": [
{
"key1": "val1"
}
],
"elements": [
{
"service": "serviceOne",
"something": "somethingValue"
},
{
"service": "THIS_SERVICE",
"attributes": [
{
"something": "somethingValue",
"attributes_here": {
"key1": "val1",
"key3": "val3",
"key4": "val4",
"key6": "val6"
}
}
]
}
]
},
"data": {
"key1": "val1"
}
}
JSON 2:
{
"responseMessage": {
"header": {
"key": "value"
},
"payload": {
"someArray": [
{
"key1": "val1"
}
],
"elements": [
{
"service": "serviceOne",
"something": "somethingValue"
},
{
"service": "THIS_SERVICE",
"attributes": [
{
"something": "somethingValue",
"attributes_here": {
"key1": "val1",
"key3": "val3",
"key4": "val4",
"key6": "val6"
}
}
]
}
]
},
"data": {
"key1": "val1"
},
"state": {
"state1": "state1"
}
},
"status": [],
"notes": []
}
Any help would be appreciated. Thank you and I wish you a great day!
2
Answers
Please try the below jolt spec:
You can remove your fields in the
remove
operation as you want.You can use the following spec as an option :