温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - How to add specific fields from input JSON to JOLT specification to get a desired output in NIFI?

其他 - 如何在输入JSON到JOLT规范中添加特定字段以在NIFI中获得所需的输出?

发布于 2020-03-27 15:38:23

我在获取数据到正确的数组时遇到麻烦。

输入:

{    "type":"insert",    "timestamp":1578899080000,    "columns":[
      {
         "id":1,
         "name":"id",
         "column_type":4,
         "value":3
       },
      {
         "id":2,
         "name":"title",
         "column_type":-1,
         "value":"mr"
       },
      {
         "id":3,
         "name":"first",
         "column_type":-1,
         "value":"todd"
       },
      {
         "id":4,
         "name":"last",
         "column_type":-1,
         "value":"graham"
       },
      {
         "id":5,
         "name":"street",
         "column_type":-1,
         "value":"5760 spring hill rd"
       },
      {
         "id":6,
         "name":"city",
         "column_type":-1,
         "value":"garden grove"
       },
      {
         "id":7,
         "name":"state",
         "column_type":-1,
         "value":"north carolina"
       },
      {
         "id":8,
         "name":"zip",
         "column_type":-1,
         "value":"81790"
       },
      {
         "id":9,
         "name":"gender",
         "column_type":-1,
         "value":"M"
       },
      {
         "id":10,
         "name":"email",
         "column_type":-1,
         "value":"todd.graham39@example.com"
       },
      {
         "id":11,
         "name":"username",
         "column_type":-1,
         "value":"purplekoala484"
       },
      {
         "id":12,
         "name":"password",
         "column_type":-1,
         "value":"paintball"
       },
      {
         "id":13,
         "name":"phone",
         "column_type":-1,
         "value":"(230)-874-6532"
       },
      {
         "id":14,
         "name":"cell",
         "column_type":-1,
         "value":"(186)-529-4912"
       },
      {
         "id":15,
         "name":"ssn",
         "column_type":-1,
         "value":"362-31-5248"
       },
      {
         "id":16,
         "name":"date_of_birth",
         "column_type":93,
         "value":"2006-07-25 05:48:01.0"
       },
      {
         "id":17,
         "name":"reg_date",
         "column_type":93,
         "value":"2004-12-05 11:26:34.0"
       },
      {
         "id":18,
         "name":"large",
         "column_type":-1,
         "value":"http://api.randomuser.me/portraits/men/39.jpg"
       },
      {
         "id":19,
         "name":"medium",
         "column_type":-1,
         "value":"http://api.randomuser.me/portraits/med/men/39.jpg"
       },
      {
         "id":20,
         "name":"thumbnail",
         "column_type":-1,
         "value":"http://api.randomuser.me/portraits/thumb/men/39.jpg"
       },
      {
         "id":21,
         "name":"version",
         "column_type":-1,
         "value":"0.6"
       },
      {
         "id":22,
         "name":"nationality",
         "column_type":-1,
         "value":"US"
       }
    ] }

所需输出:

[
   {
      "type":"insert",
      "timestamp":1578899080000,
      "id":6,
      "title":"miss",
      "first":"Amaira",
      "last":"khan",
      "street":"4524 hogan st",
      "city":"iowa park",
      "state":"ohio",
      "zip":"24140",
      "gender":"M",
      "email":"guy.mckinney53@example.com",
      "username":"blueduck623",
      "password":"office",
      "phone":"(309)-556-7859",
      "cell":"(856)-764-9146",
      "ssn":"973-37-9077",
      "date_of_birth":"1983-11-03 22:02:12.0",
      "reg_date":"2003-10-20 07:23:06.0",
      "large":"http://api.randomuser.me/portraits/men/24.jpg",
      "medium":"http://api.randomuser.me/portraits/med/men/24.jpg",
      "thumbnail":"http://api.randomuser.me/portraits/thumb/men/24.jpg",
      "version":"0.6",
      "nationality":"US"

}
]

查看更多

查看更多

提问者
Amaira
被浏览
15
Matthew Warman 2020-01-31 16:02

以下规范将@(1,name)使用值作为键来完成您想要的操作

[
  {
    "operation": "shift",
    "spec": {
      "type": "[0].type",
      "timestamp": "[0].timestamp",
      "columns": {
        "*": {
          "value": "[0].@(1,name)"
        }
      }
    }
  }
]

发布
问题

分享
好友

手机
浏览

扫码手机浏览