我想使用 JOLT 对输出 JSON 进行以下更改。您能帮助获得所需的 JSON 输出吗?谢谢你。
输入JSON:
[
[
{
"Name": "03.04.2023",
"StartTime": "2023-04-03 06:32",
"SessionData": [
{
"LocationX": "36.282466",
"LocationY": "-5.298164",
"DataValue": "0.36",
"DataType": "distance_1"
},
{
"LocationX": "36.282466",
"LocationY": "-5.298164",
"DataValue": "11.0",
"DataType": "distance_2"
},
{
"LocationX": "36.282466",
"LocationY": "-5.298164",
"DataValue": "2231",
"DataType": "distance_3"
},
{
"LocationX": "36.282466",
"LocationY": "-5.298164",
"DataValue": "0.04",
"DataType": "distance_4"
},
{
"LocationX": "36.282466",
"LocationY": "-5.298164",
"DataValue": "58.82",
"DataType": "distance_5"
},
{
"LocationX": "36.278355",
"LocationY": "-5.290660",
"DataValue": "0.00",
"DataType": "distance_1"
},
{
"LocationX": "36.278355",
"LocationY": "-5.290660",
"DataValue": "9.8",
"DataType": "distance_2"
},
{
"LocationX": "36.278355",
"LocationY": "-5.290660",
"DataValue": "2206",
"DataType": "distance_3"
},
{
"LocationX": "36.278355",
"LocationY": "-5.290660",
"DataValue": "0.00",
"DataType": "distance_4"
},
{
"LocationX": "36.278355",
"LocationY": "-5.290660",
"DataValue": "58.28",
"DataType": "distance_5"
}
]
}
]
]
预期输出 JSON:
[
{
"StartTime": "2023-04-03 06:32",
"distance_1": "0.36",
"LocationX": "36.282466",
"LocationY": "-5.298164",
"distance_2": "11.0",
"X_Z_distance": "2231",
"Y_Z_distance": "0.04",
"Temp_1": 2189,
"Distance_Type": "D",
"Distance_Length": "M"
},
{
"StartTime": "2023-04-03 06:32",
"distance_1": "0.00",
"LocationX": "36.278355",
"LocationY": "-5.290660",
"distance_2": "9.8",
"X_Z_distance": "2206",
"Y_Z_distance": "0.00",
"Temp_1": 2164,
"Distance_Type": "D",
"Distance_Length": "M"
}
]
震动:
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"*": {
"Location*": "@(1,LocationX).@(1,LocationY).&",
"@DataValue": "@(1,LocationX).@(1,LocationY).@DataType"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"Temp_1": "=doubleSum(@(1,distance_3),-42)"
}
}
}
},
{
"operation": "default",
"spec": {
"*": {
"*": {
"Distance_Length": "M",
"Distance_Type": "D"
}
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"*": {
"*": "ONE"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"distance_5": ""
}
}
}
]
您的初始 JOLT 规范未正确引用正确级别的 StartTime 字段。您试图在级别 * 访问它,但它应该在级别“0”。不包括将 distance_3 和 distance_4 分别重命名为 X_Z_distance 和 Y_Z_distance。
对 Temp_1 的修改不正确,并且您的 JOLT 规范缺少距离长度和距离类型的设置默认值。
我还删除了 distance_5,您的 JOLT 规范不包括删除所需输出中指定的 distance_5 键。
这是编辑后的 JOLT;
[
{
"operation": "shift",
"spec": {
"*": {
"0": {
"StartTime": "[&1].StartTime",
"SessionData": {
"*": {
"LocationX": "[&2].LocationX",
"LocationY": "[&2].LocationY",
"DataValue": {
"distance_1": "[&3].distance_1",
"distance_2": "[&3].distance_2",
"distance_3": "[&3].X_Z_distance",
"distance_4": "[&3].Y_Z_distance",
"*": {
"@": "[&3].&"
}
}
}
}
}
}
}
},
{
"operation": "modify-default-beta",
"spec": {
"*": {
"X_Z_distance": "=toInteger",
"Y_Z_distance": "=toInteger",
"distance_3": "=toDecimal",
"Temp_1": "=toInteger(@(1,distance_3) * 100)"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"Distance_Length": "M",
"Distance_Type": "D"
}
}
}
]