英文:
How to implement the expected output using Jolttransfromjson In Apache Nifi
问题
[
  {
    "export_time": "20230",
    "account_id": "0107F6-7",
    "cost": "0.0"
  },
  {
    "export_time": "20230101",
    "account_id": "01DC85-B",
    "cost": "3.48E-4"
  }
]
英文:
Please help me out in achieving the expected output in Jolt.
Input :
{
  "kind": "bresponse",
  "schema": {
    "fields": [
      {
        "name": "export_time",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "account_id",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "cost",
        "type": "FLOAT",
        "mode": "NULLABLE"
      }
    ]
  },
  "jobReference": {
    "projectId": "avach",
    "jobId": "job_G4hQs",
    "location": "ui"
  },
  "totalRows": "49",
  "pageToken": "BG123",
  "rows": [
    {
      "f": [
        {
          "v": "20230"
        },
        {
          "v": "0107F6-7"
        },
        {
          "v": "0.0"
        }
      ]
    },
    {
      "f": [
        {
          "v": "20230101"
        },
        {
          "v": "01DC85-B"
        },
        {
          "v": "3.48E-4"
        }
      ]
    }
  ],
  "totalBytesProcessed": "37472",
  "jobComplete": true,
  "cacheHit": false
}
Expected output :
[
  {
    "export_time": "20230",
    "account_id": "0107F6-7",
    "cost": "0.0"
  },
  {
    "export_time": "20230101",
    "account_id": "01DC85-B",
    "cost": "3.48E-4"
  }
]
Thanks
答案1
得分: 1
你可以在shift变换规范中使用以下内容:
- 
向上移动5级(遍历一次
:,四次{)以达到
通过使用[&1]从数据数组中选择子数组作为字段数组 - 
通过
[&3].节点分散所有返回的键值对 
例如
[
  {
    "operation": "shift",
    "spec": {
      "rows": {
        "*": {
          "*": {
            "*": {
              "@v": "[&3].@(5,schema.fields[&].name)"
            }
          }
        }
      }
    }
  }
]
在网站http://jolt-demo.appspot.com/上的演示如下:
英文:
You can use a shift transformation spec in which
- 
go 5 levels up (traverse once
:, and{four times ) in order to reach
fields array as picking sub-arrays of data array by using[&1] - 
dissipate all returning key-value pairs through use of
[&3].node 
such as
[
  {
    "operation": "shift",
    "spec": {
      "rows": {
        "*": {
          "*": {
            "*": {
              "@v": "[&3].@(5,schema.fields[&].name)"
            }
          }
        }
      }
    }
  }
]
the demo on the site http://jolt-demo.appspot.com/ is
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论