【问题标题】:Jolt transform json array颠簸变换json数组
【发布时间】:2021-11-23 15:39:23
【问题描述】:

我需要 Jolt 变换方面的帮助。 我有数组,它由许多 json 对象组成。 (https://jolt-demo.appspot.com/)

[
  {
    "table_name": "table_vd",
    "scratch_name": "l1_sample_1_1",
    "scratch_order": 1
  },
  {
    "table_name": "table_vd",
    "scratch_name": "l1_sample_1_1",
    "scratch_order": 34
  },
  {
    "table_name": "table_vd",
    "scratch_name": "l1_sample_2",
    "scratch_order": 3
  }
]

需要对 Jolt 进行什么变换才能得到以下结果?

{
  "table_name" : "table_vd",
  "data" : [ {
    "scratch_name" : "l1_sample_1_1",
    "scratch_order" : 1
  }, {
    "scratch_name" : "l1_sample_1_1",
    "scratch_order" : 34
  }, {
    "scratch_name" : "l1_sample_2",
    "scratch_order" : 3
  } ]
}

现在我有了下一个 Jolt 构造:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "table_name": "table_name",
        "*": {
          "@0": "data[0].&1"
        }
      }
    }
  }
]

但是下面的结果是不正确的:

{
  "table_name" : [ "table_vd", "table_vd", "table_vd" ],
  "data" : [ {
    "scratch_name" : [ "l1_sample_1_1", "l1_sample_1_1", "l1_sample_2" ],
    "scratch_order" : [ 1, 34, 3 ]
  } ]
}

【问题讨论】:

  • 请张贴您到目前为止所做的代码,并将代码从图像中删除到文本中。

标签: json apache-nifi jolt


【解决方案1】:

通过分隔"table_name" 和其他("*"),您开始使用条件逻辑。将“*”(其余)重新排列为"*": "data[&1].&",然后通过使用基数 em> 规格如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "table_name": "&",
        "*": "data[&1].&"
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "table_name": "ONE"
    }
  }
]

【讨论】:

  • 非常感谢您的回答!这对我完成任务很有帮助。
猜你喜欢
  • 1970-01-01
  • 2019-02-03
  • 2022-01-07
  • 1970-01-01
  • 2017-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多