我的输入如下所示,如果 timeMeasurementUnitCode="DAY"
那么我需要计算的值为 value*24*60
,如果 timeMeasurementUnitCode="HOUR"
然后值 value*60
我看到人们正在寻找一个类似的用例,票证于 2019 年 7 月 17 日开立
:https://github.com/bazaarvoice/jolt/issues/832
问题832现在好像还开着
输入:
{
"freightCharacteristics": {
"transitDuration": {
"timeMeasurementUnitCode": "DAY",
"value": 6
},
"loadingDuration": {
"timeMeasurementUnitCode": "HOUR",
"value": 6
}
}
}
预期输出:根据输入中提供的DAY
或HOUR
常量,我需要多个no.of days*hours*mins
code> 达到我的要求,如下所示。
{
"transitDurationInMinutes" : 8640,
"loadingDurationInMinutes" : 360
}
]
根据@mattyb的建议,我使用除法函数来实现乘法想要实现的目标,逻辑更新如下。
[
{
"operation": "shift",
"spec": {
"freightCharacteristics": {
"transitDuration": {
"timeMeasurementUnitCode": {
"DAY": {
"@(2,value)": "transitDurationInMinutes"
},
"*": {
"@(2,value)": "transitDurationInMinutes"
}
}
},
"loadingDuration": {
"timeMeasurementUnitCode": {
"HOUR": {
"@(2,value)": "loadingDurationInMinutes"
},
"*": {
"@(2,value)": "loadingDurationInMinutes"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"transitDurationInMinutes": "=divide(@(1,transitDurationInMinutes),0.00069444444)",
"loadingDurationInMinutes": "=divide(@(1,loadingDurationInMinutes),0.01666666666)"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"transitDurationInMinutes": "=toInteger",
"loadingDurationInMinutes": "=toInteger"
}
}
]
最佳答案
另一个选项是分别制作 DAY
和 HOUR
文字对象键,以便在下一步中有条件地选择它们,例如
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"value": "@(1,timeMeasurementUnitCode).&"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"DAY": {
"val": "=divide(1,@(1,value))",// 1/6 will be used to simulate a multiplication
"div": "=divide(1440,@(1,val))",
"transitDurationInMinutes": "=toInteger(@(1,div))"// to eliminate decimal representation which ends with ".0"
},
"HOUR": {
"val": "=divide(1,@(1,value))",
"div": "=divide(60,@(1,val))",
"loadingDurationInMinutes": "=toInteger(@(1,div))"
}
}
},
{// get rid of object keys
"operation": "shift",
"spec": {
"*": {
"*Duration*": "&"
}
}
}
]
网站上的演示 http://jolt-demo.appspot.com/是
关于json - Jolt Transformation Spec 中的值相乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62076560/