Need a jolt spec that will produce a "ratePeriods"
block for each "inventoryTypeCode"
, and for each period( "start"
and "end"
) date range combination.
Like here for range "start": "2025-03-08" to "end": "2025-03-08" and for ABCD type inventoryTypeCode, it will create a "ratePeriods" block containing startDate , endDate and inventoryTypeRate as first value of "value"
under "inventoryTypes"
.
For ex, for ABCD we will have two ratePeriods for each date range one for 2025-03-08 and other one for 2025-03-09 date range.
input json:
{
"pricePlans": [
{
"amountRules": [
{
"type": "AmountRule",
"period": {
"start": "2025-03-08",
"end": "2025-03-08"
},
"inventoryTypes": {
"ABCD": [
{
"computationType": "Flat",
"value": "90.00",
"occupancy": 1
},
{
"computationType": "Flat",
"value": "100.00",
"occupancy": 2
}
],
"WXYZ": [
{
"computationType": "Flat",
"value": "90.00",
"occupancy": 1
},
{
"computationType": "Flat",
"value": "100.00",
"occupancy": 2
}
]
}
},
{
"type": "AmountRule",
"period": {
"start": "2025-03-09",
"end": "2025-03-09",
"dow": "------S"
},
"inventoryTypes": {
"ABCD": [
{
"computationType": "Flat",
"value": "90.00",
"occupancy": 1
},
{
"computationType": "Flat",
"value": "100.00",
"occupancy": 2
}
],
"WZYZ": [
{
"computationType": "Flat",
"value": "135.00",
"occupancy": 1
}
]
}
}
]
}
]
}
output json:
{
"inventoryTypes": [
{
"ratePeriods": [
{
"startDate": "2025-03-08",
"endDate": "2025-03-08",
"inventoryTypeRate": "90.00"
}
],
"inventoryTypeCode": "ABCD"
},
{
"ratePeriods": [
{
"startDate": "2025-03-09",
"endDate": "2025-03-09",
"inventoryTypeRate": "90.00"
}
],
"inventoryTypeCode": "ABCD"
},
{
"ratePeriods": [
{
"startDate": "2025-03-08",
"endDate": "2025-03-08",
"inventoryTypeRate": "90.00"
}
],
"inventoryTypeCode": "WXYZ"
},
{
"ratePeriods": [
{
"startDate": "2025-03-09",
"endDate": "2025-03-09",
"inventoryTypeRate": "135.00"
}
],
"inventoryTypeCode": "WXYZ"
}
]
}
jolt spec I tried
[
{
"operation": "shift",
"spec": {
"pricePlans": {
"*": {
"amountRules": {
"*": {
"period": {
"start": "inventoryTypes[#3].ratePeriods[#2].startDate",
"end": "inventoryTypes[#3].ratePeriods[#2].endDate"
},
"inventoryTypes": {
"*": {
"0": {
"value": "inventoryTypes[#3].ratePeriods[#2].inventoryTypeRate"
}
}
}
}
}
}
}
}
}
]
but this is giving me 2 block of ratePeriods but i need 4 in this case each containing both values "inventoryTypeRate" together it has to come in differently."inventoryTypeCode": "ABCD" im populating form a different part and working perefctly so that can be ignored here, this is a part of the json.
Need a jolt spec that will produce a "ratePeriods"
block for each "inventoryTypeCode"
, and for each period( "start"
and "end"
) date range combination.
Like here for range "start": "2025-03-08" to "end": "2025-03-08" and for ABCD type inventoryTypeCode, it will create a "ratePeriods" block containing startDate , endDate and inventoryTypeRate as first value of "value"
under "inventoryTypes"
.
For ex, for ABCD we will have two ratePeriods for each date range one for 2025-03-08 and other one for 2025-03-09 date range.
input json:
{
"pricePlans": [
{
"amountRules": [
{
"type": "AmountRule",
"period": {
"start": "2025-03-08",
"end": "2025-03-08"
},
"inventoryTypes": {
"ABCD": [
{
"computationType": "Flat",
"value": "90.00",
"occupancy": 1
},
{
"computationType": "Flat",
"value": "100.00",
"occupancy": 2
}
],
"WXYZ": [
{
"computationType": "Flat",
"value": "90.00",
"occupancy": 1
},
{
"computationType": "Flat",
"value": "100.00",
"occupancy": 2
}
]
}
},
{
"type": "AmountRule",
"period": {
"start": "2025-03-09",
"end": "2025-03-09",
"dow": "------S"
},
"inventoryTypes": {
"ABCD": [
{
"computationType": "Flat",
"value": "90.00",
"occupancy": 1
},
{
"computationType": "Flat",
"value": "100.00",
"occupancy": 2
}
],
"WZYZ": [
{
"computationType": "Flat",
"value": "135.00",
"occupancy": 1
}
]
}
}
]
}
]
}
output json:
{
"inventoryTypes": [
{
"ratePeriods": [
{
"startDate": "2025-03-08",
"endDate": "2025-03-08",
"inventoryTypeRate": "90.00"
}
],
"inventoryTypeCode": "ABCD"
},
{
"ratePeriods": [
{
"startDate": "2025-03-09",
"endDate": "2025-03-09",
"inventoryTypeRate": "90.00"
}
],
"inventoryTypeCode": "ABCD"
},
{
"ratePeriods": [
{
"startDate": "2025-03-08",
"endDate": "2025-03-08",
"inventoryTypeRate": "90.00"
}
],
"inventoryTypeCode": "WXYZ"
},
{
"ratePeriods": [
{
"startDate": "2025-03-09",
"endDate": "2025-03-09",
"inventoryTypeRate": "135.00"
}
],
"inventoryTypeCode": "WXYZ"
}
]
}
jolt spec I tried
[
{
"operation": "shift",
"spec": {
"pricePlans": {
"*": {
"amountRules": {
"*": {
"period": {
"start": "inventoryTypes[#3].ratePeriods[#2].startDate",
"end": "inventoryTypes[#3].ratePeriods[#2].endDate"
},
"inventoryTypes": {
"*": {
"0": {
"value": "inventoryTypes[#3].ratePeriods[#2].inventoryTypeRate"
}
}
}
}
}
}
}
}
}
]
but this is giving me 2 block of ratePeriods but i need 4 in this case each containing both values "inventoryTypeRate" together it has to come in differently."inventoryTypeCode": "ABCD" im populating form a different part and working perefctly so that can be ignored here, this is a part of the json.
Share Improve this question edited Mar 11 at 20:03 Barbaros Özhan 65.5k11 gold badges36 silver badges61 bronze badges asked Mar 11 at 8:50 OptimizerOptimizer 2711 gold badge2 silver badges10 bronze badges 1- @Barbaros Özhan I updated the jolt I tried in the question. – Optimizer Commented Mar 11 at 13:22
1 Answer
Reset to default 0You'd better
using one more partition in such a way like
&4_&2
instead of[#3]
in which there's only onelooping through the arrays nested within the
"inventoryTypes"
object
such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"*": {
"*s": { //stands for "inventoryTypes" in order to be able to extract the literal "inventoryType"
"*": {
"0": { //take from the first object of the array
"@3,period": {
"start|end": "&5_&3.&4.ratePeriods[#3].&"
},
"value": "&4_&2.&3.ratePeriods[#2].&(3,1)Rate"
},
"$": "&3_&1.&2.&(2,1)Code"
}
}
}
}
}
}
}
},
{//get rid of the outermost wrappers
"operation": "shift",
"spec": {
"*": {
"*": "&[]"
}
}
}
]