【问题标题】:JOLT spec for nifi processorNIFI 处理器的 JOLT 规范
【发布时间】:2023-04-11 01:29:01
【问题描述】:

我有以下 JSON 输入

{
  "events": [
    {
      "cluster_id": "0717-035521-puny598",
      "timestamp": 1535540053785,
      "type": "TERMINATING",
      "details": {
        "reason": {
          "code": "INACTIVITY",
          "parameters": {
            "inactivity_duration_min": "15"
          }
        }
      }
    },
    {
      "cluster_id": "0717-035521-puny598",
      "timestamp": 1535537117300,
      "type": "EXPANDED_DISK",
      "details": {
        "previous_disk_size": 29454626816,
        "disk_size": 136828809216,
        "free_space": 17151311872,
        "instance_id": "6cea5c332af94d7f85aff23e5d8cea37"
      }
    }
  ]
}

我想把它转换成以下。

1) 在“events”数组的每个对象中添加一个静态key:value。 2) 从“events”数组的每个对象中删除一个元素“type”。 3) 其余所有值在 i/p 和 o/p 中应相同。 “细节”是一个没有特定结构的对象。

{
  "events": [
    {
      "new_key" : "new_value",
      "cluster_id": "0717-035521-puny598",
      "timestamp": 1535540053785,

      "details": {
        "reason": {
          "code": "INACTIVITY",
          "parameters": {
            "inactivity_duration_min": "15"
          }
        }
      }
    },
    {
      "new_key" : "new_value",
      "cluster_id": "0717-035521-puny598",
      "timestamp": 1535537117300,

      "details": {
        "previous_disk_size": 29454626816,
        "disk_size": 136828809216,
        "free_space": 17151311872,
        "instance_id": "6cea5c332af94d7f85aff23e5d8cea37"
      }
    }
  ]
}

【问题讨论】:

    标签: json apache-nifi jolt


    【解决方案1】:

    以下链规范应该可以工作:

    [
      {
        "operation": "default",
        "spec": {
          "events[]": {
            "*": {
              "new-key": "new-value"
            }
          }
        }
      },
      {
        "operation": "remove",
        "spec": {
          "events": {
            "*": {
              "type": ""
            }
          }
        }
      }
    ]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多