【问题标题】:NiFi how do I get JSON array of string converted to comma separated plain text value and substring(1024)NiFi 如何将字符串的 JSON 数组转换为逗号分隔的纯文本值和子字符串 (1024)
【发布时间】:2023-02-09 01:04:22
【问题描述】:

花了 5 个小时试图将字符串值的 JSON 数组转换为纯字符串逗号分隔值并通过子字符串修剪长度。

NiFi能做到吗?

例如 从...开始

[
    "Charlie was here",
    "Linus was here",
    "Snoopy was here",
    "Sally was here"
]

我正在尝试将其转换为

Charlie was here,Linus was here,Snoopy was here,Sally was here

因此,如果上述值存储到名为“myData”的属性中

然后我可以对它进行子串以缩短总长度,最后切掉什么并不重要。 例如 myData:substring(0,1024)

我一直在尝试使用以下处理器,各种组合,但一直无法找到正确的处理器来使用。

  • 更新属性
  • 评估 JSONPath
  • 拆分JSON
  • 合并内容

我得到的最接近的是 splitjson 和 mergecontent 但内容不包含分隔值的逗号,我最终得到

Charlie was hereLinus was hereSnoopy was hereSally was here

我在这里发现的几乎所有内容都涉及将文本转换为 json 但不涉及将 json 转换为文本。

我在这里缺少什么处理器?

【问题讨论】:

    标签: apache-nifi


    【解决方案1】:

    一个选项是使用颠簸变换JSON具有以下规格的处理器:

    [
      {
        "operation": "shift",
        "spec": {
          "*": "&1[]"
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": "=join(',',@(1,&))"// concatenate all string components separated  by comma
        }
      },
      {// derive the unnested string only 
        "operation": "shift",
        "spec": {
          "*": ""
        }
      }
    ]
    

    演示在网站http://jolt-demo.appspot.com/ 上是:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 1970-01-01
      • 2020-11-27
      • 2019-11-12
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多