I have some issue finding the right way to filter in my input json file using jolt as described in the following:
Input :
{
"test1": 2242,
"test2": 23456,
"description": "desc, desc, desc",
"name1": "foo",
"active": true,
"date1": "xx-xx-xx",
"date2": "xx-xx-xx",
"grade": "A",
"quantity": 10,
"information": "info, info, info",
"favorite": "Y",
"maxValue": 100,
"approachTypeMin[zone=MAR, method=a]": "12",
"approachTypeMax[zone=MAR, method=a]": "50",
"approachTypeMin[zone=NOR, method=b]": "3",
"approachTypeMax[zone=NOR, method=b]": "10"
}
This is my Spec
[
{
"operation": "shift",
"spec": {
"test1": "value1",
"test2": "value2",
"description": "desc1",
"name1": "nameValue",
"active": {
"true": {
"#Active": "status"
},
"false": {
"#Inactive": "status"
}
},
"date1": "beginDate",
"date2": "endDate",
"grade": {
"*": {
"$": "testGrade.value",
"@(2,type)": "testGrade.type",
"#2": "testGrade.defaultValue"
}
},
"quantity": "qtn",
"additionalInfo": "information",
"favorite": "fvt",
"maxValue": "max",
"approachType*, method=*]": "test.&(0,2)"
}
}
]
This is my actual Output
{
"value1" : 2242,
"value2" : 23456,
"desc1" : "desc, desc, desc",
"nameValue" : "foo",
"status" : "Active",
"beginDate" : "xx-xx-xx",
"endDate" : "xx-xx-xx",
"testGrade" : {
"value" : "A",
"defaultValue" : "2"
},
"qtn" : 10,
"fvt" : "Y",
"max" : 100,
"test" : {
"A" : [ "12", "50" ],
"B" : [ "3", "10" ]
}
}
My issue is that i can't find a way to get something like the result above depending on the grade(e.g grade A==Approach method):
{
"value1": 2242,
"value2": 23456,
"desc1": "desc, desc, desc",
"nameValue": "foo",
"status": "Active",
"beginDate": "xx-xx-xx",
"endDate": "xx-xx-xx",
"value": "X",
"testGrade": {
"type": "A",
"defaultValue": "2"
},
"qtn": "10",
"fvt": "Y",
"max": "100",
"convertedApproachMin": 12,
"convertedApproachMax": 50
}
Thanks for any help!
CodePudding user response:
Need to divide key names starting with approachType
one more time in order to seperate them by means of Min
and Max
, to derive the lower case grade to match the extracted methods (a
and b
).
So, use the following specs :
[
{
"operation": "shift",
"spec": {
"test1": "value1",
"test2": "value2",
"description": "desc1",
"name1": "nameValue",
"active": {
"true": {
"#Active": "status"
},
"false": {
"#Inactive": "status"
}
},
"date1": "beginDate",
"date2": "endDate",
"grade": "&",
"quantity": "qtn",
"additionalInfo": "information",
"favorite": "fvt",
"maxValue": "max",
"approachType*\\[zone*, method=*]": "cA&(0,1).&(0,3)"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"grade_l": "=toLower(@(1,grade))"
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"grade_l": {
"*": {
"@(2,grade)": "testGrade.value",
"#2": "testGrade.defaultValue",
"@(2,cAMin.&)": "convertedApproachMin",
"@(2,cAMax.&)": "convertedApproachMax"
}
}
}
},
{
"operation": "remove",
"spec": {
"grade": "",
"cA*": ""
}
}
]