2017-06-22 42 views
0

我想用我從其他處理器獲取的值更新JSON文件中的屬性。以下是我的原始JSON文件。需要幫助更新來自Apache NiFi中不同流文件的JSON屬性

{ 
"applicant": { 
     "applicant-id": null 
     "full-name": "Tyrion Lannister", 
     "mobile-number" : "8435739739", 
     "email-id" : "[email protected]" 
    }, 
    "product": { 
     "product-category" : "Credit Card", 
     "product-type" : "Super Value Card - Titanium" 
    } 
} 

下面是我EvaluavateJsonPath配置,我提取申請人-ID屬性。

enter image description here

下面是我GenerateFlowFile處理器,其產生一個ID值。

enter image description here

現在我需要更新的申請人-ID屬性與下面的原始JSON值(899872120)。

{ 
"applicant": { 
     "applicant-id": 899872120 
     "full-name": "Tyrion Lannister", 
     "mobile-number" : "8435739739", 
     "email-id" : "[email protected]" 
    }, 
    "product": { 
     "product-category" : "Credit Card", 
     "product-type" : "Super Value Card - Titanium" 
    } 
} 

我試圖用MergeContent合併2流和MergeContent處理器後,可看到在流文件中的申請人-ID屬性值。我嘗試使用UpdateAttribue更新申請人身份證但我無法獲取更新JSON記錄。

以下是我的MergeContent配置。

enter image description here

有什麼我失蹤?

回答

1

由於NiFi 1.2.0中,JoltTransformJSON處理器支持NiFi表達語言,所以如果你有值的屬性「申請人-ID」你的身份證,你可以在一個默認 JOLT規範使用它:

{ 
    "applicant": { 
    "applicant-id": "${Applicant-id}" 
    } 
} 

這應該將您的輸入JSON轉換爲所需的輸出JSON。

+0

Thanks Mat。但我們在我們的環境中使用1.1.0版本。無論如何,我們可以在該版本中做到嗎? – Sathyaraj

+1

您應該可以使用ReplaceText來匹配「application-id」:null並將其替換爲「application-id」:$ {Application-id}。這是一個更脆弱的,但應該適合您的輸入。 – mattyb