问题描述
我有这样的JSON
负载;
[ {
"Samples" : {
"Load" : [ {
"dataItemId" : "a5",
"timestamp" : "2019-02-17T04:58:44.097Z",
"name" : "Aload",
"sequence" : "19",
"subType" : null,
"content" : null
}, {
"dataItemId" : "a7",
"timestamp" : "2019-02-17T04:58:44.097Z",
"name" : "AAA",
"sequence" : "19",
"subType" : null,
"content" : null
} ],
"Angle" : [ {
"dataItemId" : "a6",
"timestamp" : "2019-02-17T04:58:44.097Z",
"name" : "Aact",
"sequence" : "20",
"subType" : "ACTUAL",
"content" : null
} ]
}
} ]
我想接收这样的JSON
;
{
"Samples" : [
{
"tag_name": "Load",
"dataItemId" : "a5",
"timestamp" : "2019-02-17T04:58:44.097Z",
"name" : "Aload",
"sequence" : "19",
"subType" : null,
"content" : null
}, {
"tag_name": "Load",
"dataItemId" : "a7",
"timestamp" : "2019-02-17T04:58:44.097Z",
"name" : "AAA",
"sequence" : "19",
"subType" : null,
"content" : null
}, {
"tag_name": "Angle",
"dataItemId" : "a6",
"timestamp" : "2019-02-17T04:58:44.097Z",
"name" : "Aact",
"sequence" : "20",
"subType" : "ACTUAL",
"content" : null
}
]
}
在我的场景中,我必须转换上面定义的每个json数据。
我每秒接收500个JSON数据 。
如何使用Jolt Specification
执行此操作?
震动规格很快吗?
它适合流媒体吗?
还是我应该为此编写自己的脚本 ?
1楼
如果您的有效载荷是具有单个对象的数组,则此规范适用:
[
{
"operation": "shift",
"spec": {
"*": {
"Samples": {
"*": {
"*": {
"$1": "Samples.&2[#2].tag_name",
"*": "Samples.&2[#2].&"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"Samples": {
"*": {
"*": "Samples[]"
}
}
}
}
]
否则,您可能需要拆分数组,对每个元素进行转换,然后使用MergeContent或MergeRecord将它们重新组合在一起。
或者,您可以使用JoltTransformRecord将规范应用到数组中的每个元素/记录,只需更改规范即可在第一次shift
操作中删除初始*
部分。