Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how i can extract object fom json and convert that data into attribute in NIFI

Highlighted

how i can extract object fom json and convert that data into attribute in NIFI

Explorer

renuu_0-1590094623200.png

here i have used invoked http processor for get the alarm from web app. then i have to used split processor to spilt one alarm in one flow file. and the i have used evaluatejsonpath processor of extract data into attribute after that i want to used extract value in next http invoked processor for further used ....

problem--  1. splitjson processor conf

renuu_2-1590095017865.png

2.Evaluatejsonpath conf

renuu_3-1590095126422.png

if i used destination value flowfile-attribute this not gives any data related to id ...i mean i got same output as like spiltprocessor has gave 

3.invoked http processor that connect with EvaluateJsonPath processor of id

renuu_0-1590095754944.png

{
"alarm": [
{
"attributes": {
" ": " ",
" ": " "
},
"related": [
" ",
" ",
],
"systemTime": "2020-05-21T13:57:50.444Z",
"environment": " ",
"schdul": "system",
"group": "Unknown",
"history": [
{
"schdul": "system",
"href": "https://abc.avw.com/api/alarm/46fe72b1-8999-4cde-a9e1-a3e19e31a471",
"id": "2345-3456-1234-qwer-12e3f",
"resource": "critical",
"current": "open",
"updateTime": "2020-05-21T13:57:50.444Z",
"value": "--"
}
],
"href": "href": "https://abc.avw.com/api/alarm/46fe72b1-8999-4cde-a9e1-a3e19e31a471",
"id": "2345-3456-1234-qwer-12e3f",
"lastReceiveId": "2345-3456-1234-qwer-12e3f",
"previousSeverity": "indeterminate",
"rawData": null,
"receiveTime": "2020-05-21T13:57:50.450Z",
"repeat": false,
"service": [
"example.com"
],
"resource": "critical",
"current": "open",
"text": " ",
"timeout": 86400,
"trendIndication": "moreSevere",
"type": "excepbnbntionAlert",
"updateTime": "2020-05-21T13:57:50.450Z",
"value": "--"
},

"attributes": {
" ": " ",
" ": " "
},
"related": [
" ",
" ",
],
"systemTime": "2020-05-21T13:57:50.444Z",
"environment": " ",
"schdul": "system",
"group": "Unknown",
"history": [
{
"schdul": "system",
"href": "https://abc.avw.com/api/alarm/2345-3456-2345-qwer-12e3f,
"id": "2345-3456-2345-qwer-12e3f",
"resource": "critical",
"current": "open",
"updateTime": "2020-05-21T13:57:50.444Z",
"value": "--"
}
],
 "href": "https://abc.avw.com/api/alarm/2345-3456-2345-qwer-12e3f",
"id": "2345-3456-2345-qwer-12e3f",
"lastReceiveId": "2345-3456-1234-qwer-12e3f",
"rawData": null,
"receiveTime": "2020-05-21T13:57:50.450Z",
"repeat": false,
"service": [
"example.com"
],
"resource": "critical",
"current": "open",
"text": " ",
"timeout": 86400,
"trendIndication": "moreSevere",
"type": "excepbnbntionAlert",
"updateTime": "2020-05-21T13:57:50.450Z",
"value": "--"
},
],
"autoRefresh": true,
"lastTime": "2020-05-21T13:57:50.450Z",
"more": false,
"page": 1,
"pageSize": 1000,
"pages": 1,
"resourceCounts": {
"critical": 2
},
"current": "ok",
"currentCounts": {
"open": 2
},
"total": 2
}

this is json data (the output of first invoked http processor please see in first above image)

1 REPLY 1

Re: how i can extract object fom json and convert that data into attribute in NIFI

Master Collaborator

@renuu   One of the first issues I came across with your json are some errors from the attributes and related key value pairs being empty:  

 

"attributes": {
" ": " ",
" ": " "
},
"related": [
" ",
" ",
],

There are also missing } and ], an extra "href" and missing " on value for href.  These JSON inconsistencies make it impossible to parse json without fixing them.  In my template the json I used is updated, validated within GenerateFlowFIle.  I recommend to use a JSON Validator like:   

 

https://jsonlint.com

 

Next, in order to get ID from each of the alarm's object results you need a Json Reader or another split.... evaluateJson will not match multiple IDs.   It looks like you have the split above.  To get ID after the split use :

 

$.history[0].id

 

in EvaluateJsonPath since the id is found within the history array.

 

You can find my template here ("NiFI EvaluateJsonPath Demo 2):

 

https://github.com/steven-dfheinz/NiFi-Templates

 

If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  

 

Thanks,


Steven @ DFHZ

 


 


If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  


 


Thanks,



Steven

Don't have an account?
Coming from Hortonworks? Activate your account here