Nifi JOLT:平面 JSON 对象到 JSON 对象列表 [英] Nifi JOLT: flat JSON object to a list of JSON object

查看:37
本文介绍了Nifi JOLT:平面 JSON 对象到 JSON 对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 } )

I am trying with Nifi JOLT processor to shift the flat JSON object to a list of JSON object as in below output. The params "p_7_1_0", "px_2_7_1_0", "pv_7_1_1" may be different in names or numbers (e.g. I could have { "timestamp": 1559347670, "pw_2_1_0": 1, "p_2_2_1_0": 1 } )

有人可以帮助我了解震动规格吗?

Could someone help me with the jolt specs?

输入 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 转换

和答案https://stackoverflow.com/a/50438480/2733184

我可以看出您想要的东西非常相似.但是,我永远不会对需要提出的问题一针见血.

I can see that what you want is eerily similar. However, I would have never hit the nail on the head with the question that needed to be asked.

我鼓励您阅读上述 Q 和 A,阅读所有内容(包括规范中的评论)并给他们一些赞许.

I encourage you to go to the aforementioned Q and the A, read all of it (including the comments inside the spec) and give them some upvotes.

[
  {
    "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
        }
      }
    }
  }
]

我希望有人能解释一下 # 的用途.我的直接猜测是它类似于 &(成员名称)但它看起来像是成员位置(?).

I hope someone can explain what # is for. My immediate guess is that it is like & (the member name) but it looks like it is the member position (?).

这篇关于Nifi JOLT:平面 JSON 对象到 JSON 对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆