papelr
papelr

Reputation: 438

NiFi: Extract Content of FlowFile and Add that Content to the Attributes

I am generating random data from the following JSON/AVRO schema:

{
  "type" : "record",
  "namespace" : "test",
  "name" : "metro_data",
  "fields": [
    {
      "name" : "PersonID",
      "type" : "int"
},
{
  "name" : "TripStartStation",
  "type" : {
    "type" : "enum",
    "name" : "StartStation",
    "symbols" : ["WIEHLE_RESTON_EAST", "SPRING_HILL", "GREENSBORO"]    

    }
},
{
  "name" : "TripEndStation",
  "type" : {
    "type" : "enum",
    "name" : "EndStation",
    "symbols" : ["WIEHLE_RESTON_EAST", "SPRING_HILL", "GREENSBORO""]    

      }
    }
  ]
}

The above schema generates this, for example:

[ {
  "PersonID" : -1089196095,
  "TripStartStation" : "WIEHLE_RESTON_EAST",
  "TripEndStation" : "SPRING_HILL"
}

I want to take the PersonID number of the schema, and add it to the Attributes. Eg, the blank in this photo needs to pull the actual PersonID number generated from the flow:

enter image description here

I have tried to use EvaluateJSONPath with the following configuration, and that's how I end up with the empty string set under PersonalID:

enter image description here

Is my next processor UpdateAttribute? Not sure how to pull that content. Thanks!

Upvotes: 2

Views: 17506

Answers (1)

notNull
notNull

Reputation: 31540

You are having array of json message(s)(ex: [...]) and You need to split the array of json into individual flowfiles using SplitJson processor with split expression as $.*

Then use EvaluateJsonProcessor to extract PersonID value as a attribute.

Flow:

--> SplitJson --> EvaluateJsonPath--> other processors

For more details refer to this link regards to the same issue.

Upvotes: 5

Related Questions