2017-05-24 44 views
1

我想用颠簸处理器Nifi实现以下JSON改造颠簸转型 - 以单独的分支匹配值 - JSON

输入JSON

{ 
    "topLevel": { 
     "secondLevelA": { 
      "thirdLevelA": [ 
       { 
        "norsemen": "huntinSouth", 
        "value": "AAA" 
       }, 
       { 
        "norsemen": "huntinNorth", 
        "value": "BBB" 
       } 
       ] 
     }, 
     "secondLevelB": { 
      "thirdLevelB": [ 
       { 
        "norsemen": "huntinNorth", 
        "oddCode": "AAA301" 
       }, 
       { 
        "norsemen": "huntinNorth", 
        "oddCode": "BBB701" 
       }, 
       { 
        "norsemen": "huntinWest", 
        "oddCode": "AAA701" 
       } 
      ] 
     } 
    } 
} 

输出JSON

{ 
    "NAME": [ 
     { 
      "norsemen": "huntinSouth", 
      "value": "AAA", 
      "refValue": [] 
     }, 
     { 
      "norsemen": "huntinNorth", 
      "value": "BBB", 
      "refValue": [ 
       { 
        "oddCode": [ 
         "BBB701" 
        ] 
       } 
      ] 
     } 
    ] 
} 

我会喜欢测试secondLevelA.thirdLevelA.norsemen的值之间的匹配secondLevel B.thirdLevelB.norsemen。如果找到一个或多个匹配,则包含在与匹配的norsemen相同的集合中的所有值为secondLevelB.thirdLevelB.oddCode将被放置在与相应匹配的norsemen相同的集合中的输出中。

有没有办法使用现有的Jolt操作来做到这一点?

回答

0

看起来你有一些非声明性的逻辑不能被颠覆覆盖。

From jolt description:

颠簸:

  • 侧重于将您的JSON数据的结构,而不是操纵特定值
    • 的想法是:利用颠簸让大部分结构然后编写代码来修复值

股票变换是:

shift  : copy data from the input tree and put it the output tree 
default  : apply default values to the tree 
remove  : remove data from the tree 
sort  : sort the Map key values alphabetically (for debugging and human readability) 
cardinality : "fix" the cardinality of input data. Eg, the "urls" element is usually a List, but if there is only one, then it is a String 

我在这里看不到那种if/then/else

所以,我觉得你的任务无法覆盖只是jolt

对我来说,最简单的方法是使用JavaScript或Groovy语言的脚本处理器。