Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Apache Nifi

avatar
Explorer

Hello ,

I am working on jolt transforms processor,

my input is:

{

  "dataSourceName": "Standard CPU Utilization Network Cisco",

  "dataPoints": [

    "CPU1min",

    "CPU5min",

    "MemoryFree",

    "MemoryUsed",

    "MemoryTotal"

  ],

  "instances": {

    "Standard CPU Utilization Network Cisco-NPE400 0 Index9": {

      "values": [

        [

          "No Data",

          "No Data",

          "No Data",

          "No Data",

          "No Data"

        ],

        [

          "No Data",

          "No Data",

          "No Data",

          "No Data",

          "No Data"

        ],

        [

          "No Data",

          "No Data",

          "No Data",

          "No Data",

          "No Data"

        ],

        [

          "No Data",

          "No Data",

          "No Data",

          "No Data",

          "No Data"

        ],

        [

          "No Data",

          "No Data",

          "No Data",

          "No Data",

          "No Data"

        ],

        [

          "No Data",

          "No Data",

          "No Data",

          "No Data",

          "No Data"

        ],   

   

      "time": [

        1662618899000,

        1662618839000,

        1662618779000,

        1662618719000,

        1662618659000,

        1662618599000,

        1662618539000,

        1662615570000,

        1662615510000,

        1662615450000,

        1662615390000

      ]

    }

  }

}

Condition:

The requirement is we need to use if else statement like

if [datasourcename] == Standard CPU Utilization Network Cisco then

Expected output:

{

“Datasourcename” :  “Standard CPU Utilization Network Cisco”,

“Datapoints” :     "MemoryFree",

“Parametername” : “Standard CPU Utilization Network Cisco-NPE400 0 Index9”

“Datas”: values[3],

}

How can I achieve using jolt transforms processor, Pls help me out.

1 REPLY 1

avatar

Hi,

To help you I think we need to understand your question better, so you have a json input like you specified above, from what I understand there are two parts you are trying to solve:

1- You need to process this json if it meets certain condition, in this case the condition is if the Json attribute "dataSourceName" is equal to "Standard CPU Utilization Network Cisco".

2- If the json meets the condition above then you want to apply Json Jolt Transformation to produce the output you specified, is this correct?

 

To answer the first part, I'm not sure if you can have conditional json jolt so you can do the first and the second part in one processor. I think what you need to do is use EvaluateJsonPath processor to extract the value that you need  -dataSourceName- into a flow file attribute then use RouteOnAttribute to check the value so that if meets the condition (="Standard CPU Utilization Network Cisco" ) the match relationship will direct the flow file to the Jolt transformation processor to apply needed transformation , otherwise the flowfile will be dropped or direct to unmatched relationship for farther processing.

 

For the second part, its not clear if you need the exact output you specified no matter what the other  values in the input json are , which in this case you can use the ReplaceText processor just to replace the whole input json with the expected out, Or you actually need json jolt transformation to capture different values for each json input which in this case its not clear how you are selecting your values, for example on what basis you decided that the value of "Datapoints" is "MemoryFree", also how the attribute "Datas" has the value of "Values[3]". So you need to clarify that better so we can help you with creating the proper jolt spec.

 

Hope that helps.

Thanks