[英]JOLT transform object into an array
I am trying to transform the following object into an array, the object is formatted already as required just needs to be output as an array containing that object.我正在尝试将以下 object 转换为一个数组,object 已根据需要格式化,只需将 output 作为包含该 object 的数组即可。
[
{
"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
}
]
I would like the output to be an array containing the one object. Currently my spec is:我希望 output 是一个包含 object 的数组。目前我的规范是:
[
{
"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"
}
}
}
}
]
Which gets me the following, but you can see the result is not an array.这让我得到以下结果,但你可以看到结果不是一个数组。
{
"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
}
]
}
]
}
The output I am trying for is:我正在尝试的 output 是:
[
{
"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
}
]
}
]
}
]
eg which needs to be enclosed in a set of []
例如,它需要包含在一组
[]
中
You can你可以
[0].
[0].
for the second tranformation spec in order to nest the whole content within the square brackets such as{
"operation": "shift",
"spec": {
"LevelID": "[0].assetId",
"PLCTime": "[0].dataPoints[].timestamp",
"name": {
"*": {
"@": "[0].dataPoints[0].measures[&].&2",
"@(3,value[&])": "[0].dataPoints[0].measures[&].value"
}
}
}
}
or或者
{
"operation": "shift",
"spec": {
"@": "[]"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.