Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Nifi - How to add key:value to json

avatar

Hi, we need to add a default key:value with actual timestamp to the following json input structure:

[ {
  "host" : "DUSTSADMIN.ads.xyz.de",
  "host_icons" : "menu",
  "host_state" : "UP",
  "num_services_crit" : "0",
  "num_services_ok" : "28",
  "num_services_pending" : "0",
  "num_services_unknown" : "0",
  "num_services_warn" : "0"
}, {
  "host" : "DUSTSVMDC01.ads.xyz.de",
  "host_icons" : "menu",
  "host_state" : "UP",
  "num_services_crit" : "0",
  "num_services_ok" : "34",
  "num_services_pending" : "0",
  "num_services_unknown" : "0",
  "num_services_warn" : "0"
}, {
  "host" : "DUSTSVMDC02.ads.xyz.de",
  "host_icons" : "menu",
  "host_state" : "UP",
  "num_services_crit" : "0",
  "num_services_ok" : "34",
  "num_services_pending" : "0",
  "num_services_unknown" : "0",
  "num_services_warn" : "0"
} ]

needed output:

[ { "ctime" : "Current_timestamp",
  "host" : "DUSTSADMIN.ads.xyz.de",
  "host_icons" : "menu",
  "host_state" : "UP",
  "num_services_crit" : "0",
  "num_services_ok" : "28",
  "num_services_pending" : "0",
  "num_services_unknown" : "0",
  "num_services_warn" : "0"
}, {"ctime" : "Current_timestamp",
  "host" : "DUSTSVMDC01.ads.xyz.de",
  "host_icons" : "menu",
  "host_state" : "UP",
  "num_services_crit" : "0",
  "num_services_ok" : "34",
  "num_services_pending" : "0",
  "num_services_unknown" : "0",
  "num_services_warn" : "0"
}, {"ctime" : "Current_timestamp",
  "host" : "DUSTSVMDC02.ads.xyz.de",
  "host_icons" : "menu",
  "host_state" : "UP",
  "num_services_crit" : "0",
  "num_services_ok" : "34",
  "num_services_pending" : "0",
  "num_services_unknown" : "0",
  "num_services_warn" : "0"
} ]

1 ACCEPTED SOLUTION

avatar
Master Guru

As of NiFi 1.2.0, you can use Expression Language in JOLT specifications (NIFI-3010). The following Chain spec adds the ctime field to your input with the current timestamp:

[{
    "operation": "default",
    "spec": {
      "*": {
        "ctime": "${now()}"
      }
    }
}]

If you want ctime you have an integer rather than a string, you can use the following EL expression:

${now():toNumber()}

View solution in original post

5 REPLIES 5

avatar
Master Guru

As of NiFi 1.2.0, you can use Expression Language in JOLT specifications (NIFI-3010). The following Chain spec adds the ctime field to your input with the current timestamp:

[{
    "operation": "default",
    "spec": {
      "*": {
        "ctime": "${now()}"
      }
    }
}]

If you want ctime you have an integer rather than a string, you can use the following EL expression:

${now():toNumber()}

avatar

Hi Matt,

now i got only this output :

[{

"ctime":"${now()}",

"host":"DUSTSADMIN.ads.xyz.de",

"host_icons":"menu",

"host_state":"UP",

"num_services_crit":"0",

"num_services_ok":"28",

"num_services_pending":"0",

"num_services_unknown":"0",

"num_services_warn":"0"

},

"ctime":"${now()}",

"host":"DUSTSVMDC01.ads.xyz.de",

"host_icons":"menu",

"host_state":"UP",

"num_services_crit":"0",

"num_services_ok":"34",

"num_services_pending":"0",

"num_services_unknown":"0",

"num_services_warn":"0"

},{"ctime":"${now()}",

"host":"DUSTSVMDC02.ads.xyz.de",

"host_icons":"menu",

"host_state":"UP",

"num_services_crit":"0",

"num_services_ok":"34",

"num_services_pending":"0",

"num_services_unknown":"0",

"num_services_warn":"0"

}]

maybe there ist something wrong with ""?

regards Timo

avatar

I think my problem my version is : nifi-1.1.2

avatar

Hi Matt,

after upgrading to nifi 1.2 all works fine !!!

Great work! Thanks

avatar

Hi Matt,

now i got only this output :

[{

"ctime":"${now()}",

"host":"DUSTSADMIN.ads.xyz.de",

"host_icons":"menu",

"host_state":"UP",

"num_services_crit":"0",

"num_services_ok":"28",

"num_services_pending":"0",

"num_services_unknown":"0",

"num_services_warn":"0"

},

"ctime":"${now()}",

"host":"DUSTSVMDC01.ads.xyz.de",

"host_icons":"menu",

"host_state":"UP",

"num_services_crit":"0",

"num_services_ok":"34",

"num_services_pending":"0",

"num_services_unknown":"0",

"num_services_warn":"0"

},{"ctime":"${now()}",

"host":"DUSTSVMDC02.ads.xyz.de",

"host_icons":"menu",

"host_state":"UP",

"num_services_crit":"0",

"num_services_ok":"34",

"num_services_pending":"0",

"num_services_unknown":"0",

"num_services_warn":"0"

}]

maybe there ist something wrong with ""?

regards Timo