我正在尝试使用 Nifi JOLT 处理器将平面 JSON 对象转换为 JSON 对象列表,如下面的输出所示。参数 "p_7_1_0"
、"px_2_7_1_0"
、"pv_7_1_1"
的名称或编号可能不同(例如,我可以有 { “时间戳”: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
}
]
}
提前致谢
最佳答案
读完这个问题后JOLT transformation to copy single value along an array
以及答案 https://stackoverflow.com/a/50438480/2733184
我发现你想要的东西出奇地相似。然而,我永远不会提出需要提出的问题。
我鼓励您阅读前面提到的问题和答案,阅读所有内容(包括规范中的评论)并给他们一些支持。
[
{
"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
}
}
}
}
]
我希望有人能解释一下#
的用途。我的直接猜测是它类似于 &
(成员名称),但看起来像是成员职位(?)。
关于json - 尼菲震动 : flat JSON object to a list of JSON object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66580735/