I am converting two array of objects into a single array of objects. While doing so, based on the type of the item , I need to assign a id for each item. And, after putting the items in a single array, the ids should be serial, in the order they originally appeared in the input json. its not single itemId for all the items. It s based on its own type. PFB the input and output JSON samples. Using jolt-core [0.1.0] . Please help.
Input Json:
{
"Beverages" : {
"Items" : [ {
"name" : "cofee",
"type" : "hot"
},{
"name" : "wine",
"type" : "cold"
},{
"name" : "tea",
"type" : "hot"
},{
"name" : "beer",
"type" : "cold"
}
]
},
"Snacks" : {
"Items" : [ {
"name" : "crackers",
"type" : "hot"
},{
"name" : "salad",
"type" : "cold"
},{
"name" : "muffin",
"type" : "cold"
},{
"name" : "toast",
"type" : "hot"
}
]
}
}
And, the expected output is:
{
"items" : [{
"name" : "cofee",
"type" : "hot",
"hotId" : 1
},{
"name" : "wine",
"type" : "cold",
"coldId" : 1
},{
"name" : "tea",
"type" : "hot",
"hotId" : 2
},{
"name" : "beer",
"type" : "cold",
"coldId" : 2
},{
"name" : "crackers",
"type" : "hot",
"hotId" : 3
},{
"name" : "salad",
"type" : "cold",
"coldId" : 3
},{
"name" : "muffin",
"type" : "cold",
"coldId" : 4
},{
"name" : "toast",
"type" : "hot",
"hotId" : 4
}
]
}
As above, the hotId and coldId are the new fields in the output. But, it increments.
question from:
https://stackoverflow.com/questions/65921966/counter-while-transforming-with-jolt