如何使用 Jolt 规范将 Json 转换为 Json?
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
执行此操作? Jolt 规范 快速 吗?它适合流式传输吗?或者我应该为此编写自己的脚本吗?
如果您的负载是包含单个对象的数组,则此规范有效:
[
{
"operation": "shift",
"spec": {
"*": {
"Samples": {
"*": {
"*": {
"": "Samples.&2[#2].tag_name",
"*": "Samples.&2[#2].&"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"Samples": {
"*": {
"*": "Samples[]"
}
}
}
}
]
否则您可能需要拆分数组,对每个元素进行转换,然后使用 MergeContent 或 MergeRecord 将它们重新组合在一起。或者,您可以使用 JoltTransformRecord,它将规范应用于数组中的每个 element/record,只需更改规范以删除第一个 shift
操作中的初始 *
部分。
我有 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
执行此操作? Jolt 规范 快速 吗?它适合流式传输吗?或者我应该为此编写自己的脚本吗?
如果您的负载是包含单个对象的数组,则此规范有效:
[
{
"operation": "shift",
"spec": {
"*": {
"Samples": {
"*": {
"*": {
"": "Samples.&2[#2].tag_name",
"*": "Samples.&2[#2].&"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"Samples": {
"*": {
"*": "Samples[]"
}
}
}
}
]
否则您可能需要拆分数组,对每个元素进行转换,然后使用 MergeContent 或 MergeRecord 将它们重新组合在一起。或者,您可以使用 JoltTransformRecord,它将规范应用于数组中的每个 element/record,只需更改规范以删除第一个 shift
操作中的初始 *
部分。