JOLT 将对象转换为数组
JOLT transform object into an array
我正在尝试将以下对象转换为数组,该对象已按要求格式化,只需将其输出为包含该对象的数组即可。
[
{
"PLCTime": 1643804542000,
"LevelID": "53.99.2",
"Data1Type": "Axis1 Dist",
"Data1": 1,
"Data2Type": "Axis2 Dist",
"Data2": 2,
"Data3Type": "Axis3 Dist",
"Data3": 3,
"Data4Type": "Axis4 Dist",
"Data4": 4,
"Data5Type": "Axis5 Dist",
"Data5": 5.5,
"Data6Type": "Axis6 Dist",
"Data6": 6
}
]
我希望输出是一个包含一个对象的数组。目前我的规格是:
[
{
"operation": "shift",
"spec": {
"*": {
"Data*Type": {
"@(0)": "name"
},
"Data*": {
"@(0)": "value"
},
"*": "&"
}
}
},
{
"operation": "shift",
"spec": {
"LevelID": "assetId",
"PLCTime": "dataPoints[].timestamp",
"name": {
"*": {
"@": "dataPoints[0].measures[&].&2",
"@(3,value[&])": "dataPoints[0].measures[&].value"
}
}
}
}
]
得到以下结果,但您可以看到结果不是数组。
{
"assetId": "53.99.2",
"dataPoints": [
{
"timestamp": 1643804542000,
"measures": [
{
"name": "Axis1 Dist",
"value": 1
},
{
"name": "Axis2 Dist",
"value": 2
},
{
"name": "Axis3 Dist",
"value": 3
},
{
"name": "Axis4 Dist",
"value": 4
},
{
"name": "Axis5 Dist",
"value": 5.5
},
{
"name": "Axis6 Dist",
"value": 6
}
]
}
]
}
我正在尝试的输出是:
[
{
"assetId": "53.99.2",
"dataPoints": [
{
"timestamp": 1643804542000,
"measures": [
{
"name": "Axis1 Dist",
"value": 1
},
{
"name": "Axis2 Dist",
"value": 2
},
{
"name": "Axis3 Dist",
"value": 3
},
{
"name": "Axis4 Dist",
"value": 4
},
{
"name": "Axis5 Dist",
"value": 5.5
},
{
"name": "Axis6 Dist",
"value": 6
}
]
}
]
}
]
例如需要包含在一组[]
中
你可以
- 在 right-hand 侧的标识符前加上
[0].
作为
第二次转换规范,以便将整个内容嵌套在
方括号如
{
"operation": "shift",
"spec": {
"LevelID": "[0].assetId",
"PLCTime": "[0].dataPoints[].timestamp",
"name": {
"*": {
"@": "[0].dataPoints[0].measures[&].&2",
"@(3,value[&])": "[0].dataPoints[0].measures[&].value"
}
}
}
}
或
- 将以下规范添加到当前规范中,或者
{
"operation": "shift",
"spec": {
"@": "[]"
}
}
我正在尝试将以下对象转换为数组,该对象已按要求格式化,只需将其输出为包含该对象的数组即可。
[
{
"PLCTime": 1643804542000,
"LevelID": "53.99.2",
"Data1Type": "Axis1 Dist",
"Data1": 1,
"Data2Type": "Axis2 Dist",
"Data2": 2,
"Data3Type": "Axis3 Dist",
"Data3": 3,
"Data4Type": "Axis4 Dist",
"Data4": 4,
"Data5Type": "Axis5 Dist",
"Data5": 5.5,
"Data6Type": "Axis6 Dist",
"Data6": 6
}
]
我希望输出是一个包含一个对象的数组。目前我的规格是:
[
{
"operation": "shift",
"spec": {
"*": {
"Data*Type": {
"@(0)": "name"
},
"Data*": {
"@(0)": "value"
},
"*": "&"
}
}
},
{
"operation": "shift",
"spec": {
"LevelID": "assetId",
"PLCTime": "dataPoints[].timestamp",
"name": {
"*": {
"@": "dataPoints[0].measures[&].&2",
"@(3,value[&])": "dataPoints[0].measures[&].value"
}
}
}
}
]
得到以下结果,但您可以看到结果不是数组。
{
"assetId": "53.99.2",
"dataPoints": [
{
"timestamp": 1643804542000,
"measures": [
{
"name": "Axis1 Dist",
"value": 1
},
{
"name": "Axis2 Dist",
"value": 2
},
{
"name": "Axis3 Dist",
"value": 3
},
{
"name": "Axis4 Dist",
"value": 4
},
{
"name": "Axis5 Dist",
"value": 5.5
},
{
"name": "Axis6 Dist",
"value": 6
}
]
}
]
}
我正在尝试的输出是:
[
{
"assetId": "53.99.2",
"dataPoints": [
{
"timestamp": 1643804542000,
"measures": [
{
"name": "Axis1 Dist",
"value": 1
},
{
"name": "Axis2 Dist",
"value": 2
},
{
"name": "Axis3 Dist",
"value": 3
},
{
"name": "Axis4 Dist",
"value": 4
},
{
"name": "Axis5 Dist",
"value": 5.5
},
{
"name": "Axis6 Dist",
"value": 6
}
]
}
]
}
]
例如需要包含在一组[]
你可以
- 在 right-hand 侧的标识符前加上
[0].
作为 第二次转换规范,以便将整个内容嵌套在 方括号如
{
"operation": "shift",
"spec": {
"LevelID": "[0].assetId",
"PLCTime": "[0].dataPoints[].timestamp",
"name": {
"*": {
"@": "[0].dataPoints[0].measures[&].&2",
"@(3,value[&])": "[0].dataPoints[0].measures[&].value"
}
}
}
}
或
- 将以下规范添加到当前规范中,或者
{
"operation": "shift",
"spec": {
"@": "[]"
}
}