如何使用Apache Nifi中的JoltTransformJSON来实现预期输出。

huangapple go评论56阅读模式
英文:

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/上的演示如下:

如何使用Apache Nifi中的JoltTransformJSON来实现预期输出。

英文:

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

如何使用Apache Nifi中的JoltTransformJSON来实现预期输出。

huangapple
  • 本文由 发表于 2023年3月4日 00:27:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75629595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定