Reputation: 97
Using the below input trying to generate the desired output, condition based in the array of values is not working. can you provide some inputs on this. Based on customer and promotion type need to append the amount values
{
"Id": "100",
"name": "Test",
"discounts": [
{
"TypeCode": "customer",
"Amount": 20
},
{
"TypeCode": "promotion",
"Amount": 10
}
],
"items": [
{
"LineId": "1001",
"lineItem": "TestProduct",
"discountDetails": [
{
"LineTypeCode": "customer",
"discountAmount": 300
},
{
"LineTypeCode": "customer",
"discountAmount": 330
}
]
}
]
}
Desired output format :
{
"Id": "100",
"name": "Test",
customerAmount : 20,
promotionAmount : 10,
"items": [
{
"LineId": "1001",
"lineItem": "TestProduct",
"customerlineamount" : 300,
"foclineamount" : 330
}
]
}
Upvotes: 0
Views: 89
Reputation: 65408
The conditional logic is needed in order to extract the third and fourth elements with Amount
keys such as
"discounts": {
"*": {
"TypeCode": {
"customer": {
"@(2,Amount)": "customerAmount"
},
"promotion": {
"@(2,Amount)": "promotionAmount"
}
}
}
}
and define items
array through prepending items.[&1]
for each key, which should be in the result set, in order to go one level up. So, use the following complete specification of Jolt such as
[{
"operation": "shift",
"spec": {
"Id": "Id",
"name": "name",
"discounts": {
"*": {
"TypeCode": {
"customer": {
"@(2,Amount)": "customerAmount"
},
"promotion": {
"@(2,Amount)": "promotionAmount"
}
}
}
},
"items": {
"*": {
"LineId": "items.[&1].LineId",
"lineItem": "items.[&1].lineItem",
"@(2,items[0].discountDetails[0].discountAmount)": "items.[&1].customerlineamount",
"@(2,items[0].discountDetails[1].discountAmount)": "items.[&1].foclineamount"
}
}
}
}]
Upvotes: 0