Nifi JOLT:将JSON对象转换为JSON对象列表 [英] Nifi JOLT: flat JSON object to a list of JSON object

查看:96
本文介绍了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
      }
    ]
}

预先感谢

推荐答案

在阅读完此问题后和答案 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天全站免登陆