[英]How to transform Json to Json using Jolt Specification?
我有這樣的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
執行此操作? 震動規格很快嗎? 它適合流媒體嗎? 還是我應該為此編寫自己的腳本 ?
如果您的有效載荷是具有單個對象的數組,則此規范適用:
[
{
"operation": "shift",
"spec": {
"*": {
"Samples": {
"*": {
"*": {
"$1": "Samples.&2[#2].tag_name",
"*": "Samples.&2[#2].&"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"Samples": {
"*": {
"*": "Samples[]"
}
}
}
}
]
否則,您可能需要拆分數組,對每個元素進行轉換,然后使用MergeContent或MergeRecord將它們重新組合在一起。 或者,您可以使用JoltTransformRecord將規范應用到數組中的每個元素/記錄,只需更改規范即可在第一次shift
操作中刪除初始*
部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.