将Nifi中的列分成两列(数组)。

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

Nifi - Separate the column in two colums (Array)

问题

I can help you with the translation part. Here's the translation of the provided text:

  1. 我有一个 JSON
  2. {
  3. "consultor_do_projeto": [
  4. "Iago de Oliveira",
  5. "Murilo Tavares"
  6. ]
  7. }
  8. 我需要转换成:
  9. {
  10. "consultor0" : "Iago de Oliveira",
  11. "consultor1" : "Murilo Tavares"
  12. }
  13. Jolt 规范中,我可以这样做吗?
  14. 如果第三项存在,它将是 `consultor2`
  15. 感谢您的帮助!
英文:

I have a JSON :

  1. {
  2. "consultor_do_projeto": [
  3. "Iago de Oliveira",
  4. "Murilo Tavares"
  5. ]
  6. }

I need to transform in:

  1. {
  2. "consultor0" : "Iago de Oliveira",
  3. "consultor1" : "Murilo Tavares"
  4. }

In Jolt Spec, Can I do this?

if the third item exists, it will be the consultor2

Thanks to help!

答案1

得分: 3

是的,您可以通过使用Jolt规范来实现,例如:

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "*_do_projeto": {
  6. "*": {
  7. "@": "&(2,1)"
  8. }
  9. }
  10. }
  11. }
  12. ]

其中:

  • &(2,1) 从上面的2级中提取第1个星号的替换内容(例如,子字符串 "consultor")

以及

  • & 旁边的内容提取了与 @ 符号对应的索引值(0,1,..)的数组中的值。

网站http://jolt-demo.appspot.com/上的演示如下:

将Nifi中的列分成两列(数组)。

英文:

Yes, you can do through use of a Jolt spec such as

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "*_do_projeto": {
  6. "*": {
  7. "@": "&(2,1)&"
  8. }
  9. }
  10. }
  11. }
  12. ]

where

  • &(2,1) brings the 1st asterisk replacement from the 2 levels up (eg. the substring "consultor")

and

  • & next to that brings the counterpart value for @ sign which refers the indexes (0,1,..) of the array.

the demo on the site http://jolt-demo.appspot.com/ is

将Nifi中的列分成两列(数组)。

huangapple
  • 本文由 发表于 2023年6月6日 04:49:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409910.html
匿名

发表评论

匿名网友

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

确定