Nifi JOLT:将 JSON 个对象扁平化为 JSON 个对象的列表
Nifi JOLT: flat JSON object to a list of JSON object
我正在尝试使用 Nifi JOLT 处理器将平面 JSON 对象移动到 JSON 对象列表,如下面的输出所示。参数 "p_7_1_0"
、"px_2_7_1_0"
、"pv_7_1_1"
的名称或数字可能不同(例如,我可以 { "timestamp": 1559347670, "pw_2_1_0" : 1, "p_2_2_1_0": 1 } )
有人可以帮助我了解震动规格吗?
输入Json:
{
"timestamp": 1559347670,
"p_7_1_0": 6,
"px_2_7_1_0": 1,
"pv_7_1_1": 1
}
预期输出JSON:
{
"values": [
{
"key": "p_7_1_0",
"value": 6,
"timestamp": 1559347670
},
{
"key": "px_2_7_1_0",
"value": 1,
"timestamp": 1559347670
},
{
"key": "pv_7_1_1",
"value": 1,
"timestamp": 1559347670
}
]
}
提前致谢
阅读完这个问题后
和答案
我看得出你想要的东西出奇地相似。但是,我永远不会把需要问的问题一针见血。
我鼓励你去看前面提到的 Q 和 A,阅读所有内容(包括规范中的评论)并给他们一些赞。
[
{
"operation": "shift",
"spec": {
"timestamp": "timestamp",
// put everything but the timestamp in a member (the pivot)
"*": "all.&"
}
},
{
"operation": "shift",
"spec": {
"all": {
"*": {
// grab the member key and put it in its final place
"$": "values[#2].key",
// grab the member value and put it in its final place
"@": "values[#2].value",
// Walk back two steps (* -> all -> root) and grab the timestamp
"@(2,timestamp)": "values[#2].timestamp"
// I wish I understood the logic behind "#2" but I don't
// and I'll have to read on it further
}
}
}
}
]
希望有人能解释一下#
是干什么用的。我的直接猜测是它像 &
(成员名称)但它看起来像是成员位置(?)。
我正在尝试使用 Nifi JOLT 处理器将平面 JSON 对象移动到 JSON 对象列表,如下面的输出所示。参数 "p_7_1_0"
、"px_2_7_1_0"
、"pv_7_1_1"
的名称或数字可能不同(例如,我可以 { "timestamp": 1559347670, "pw_2_1_0" : 1, "p_2_2_1_0": 1 } )
有人可以帮助我了解震动规格吗?
输入Json:
{
"timestamp": 1559347670,
"p_7_1_0": 6,
"px_2_7_1_0": 1,
"pv_7_1_1": 1
}
预期输出JSON:
{
"values": [
{
"key": "p_7_1_0",
"value": 6,
"timestamp": 1559347670
},
{
"key": "px_2_7_1_0",
"value": 1,
"timestamp": 1559347670
},
{
"key": "pv_7_1_1",
"value": 1,
"timestamp": 1559347670
}
]
}
提前致谢
阅读完这个问题后
和答案
我看得出你想要的东西出奇地相似。但是,我永远不会把需要问的问题一针见血。
我鼓励你去看前面提到的 Q 和 A,阅读所有内容(包括规范中的评论)并给他们一些赞。
[
{
"operation": "shift",
"spec": {
"timestamp": "timestamp",
// put everything but the timestamp in a member (the pivot)
"*": "all.&"
}
},
{
"operation": "shift",
"spec": {
"all": {
"*": {
// grab the member key and put it in its final place
"$": "values[#2].key",
// grab the member value and put it in its final place
"@": "values[#2].value",
// Walk back two steps (* -> all -> root) and grab the timestamp
"@(2,timestamp)": "values[#2].timestamp"
// I wish I understood the logic behind "#2" but I don't
// and I'll have to read on it further
}
}
}
}
]
希望有人能解释一下#
是干什么用的。我的直接猜测是它像 &
(成员名称)但它看起来像是成员位置(?)。