2017-05-24 32 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語言的腳本處理器。