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.

What is the RouteOnContent syntax to check if JSON element is an object or an array

What is the RouteOnContent syntax to check if JSON element is an object or an array

New Contributor

The data I have is as follows:

107862-1555088185445.png

In the above case $[0].fltdOutput.fltdMessage is an array, shown in its original form.


I will see this in two forms: object and array.


In the following case $[0].fltdOutput.fltdMessage is an object.


[ {
  "fltdOutput" : {
    "fltdMessage" : {
      "ncsmFlightTimes" : {
        "qualifiedAircraftId" : {
          "aircraftId" : "DAL2160",
          "computerId" : {
            "facilityIdentifier" : "TFMS",
            "idNumber" : 927
          },
          "gufi" : "KF45658600",
          "igtd" : "2019-04-12T13:30:00Z",
          "departurePoint" : {
            "airport" : "KDFW"
          },
          "arrivalPoint" : {
            "airport" : "KSLC"
          }
        },
        "flightStatusAndSpec" : {
          "flightStatus" : "FILED",
          "aircraftModel" : "A319",
          "aircraftspecification" : "A319"
        },
        "etd" : null,
        "eta" : null,
        "ctd" : "1970-01-01T00:00:00Z",
        "cta" : "1970-01-01T00:00:00Z",
        "rvsmData" : null,
        "departureFixAndTime" : null,
        "arrivalFixAndTime" : null
      }
    }
  }
} ]

Sometimes $[0].fltdOutput.fltdMessage is an array:

[ {
  "fltdOutput" : {
    "fltdMessage" : [ {
      "trackInformation" : {
        "qualifiedAircraftId" : {
          "aircraftId" : "SWA2148",
          "computerId" : {
            "facilityIdentifier" : "KZDC",
            "idNumber" : 507
          },
          "gufi" : "KJ42198600",
          "igtd" : "2019-04-12T12:35:00Z",
          "departurePoint" : {
            "airport" : "KMCO"
          },
          "arrivalPoint" : {
            "airport" : "KROC"
          }
        },
        "speed" : 476,
        "reportedAltitude" : {
          "assignedAltitude" : {
            "simpleAltitude" : "390C"
          }
        },
        "position" : {
          "latitude" : {
            "latitudeDMS" : "MapRecord[{seconds=31, minutes=04, degrees=34, direction=NORTH}]"
          },
          "longitude" : {
            "longitudeDMS" : "MapRecord[{seconds=09, minutes=51, degrees=080, direction=WEST}]"
          }
        },
        "timeAtPosition" : "2019-04-12T13:48:58Z",
        "ncsmTrackData" : {
          "eta" : "MapRecord[{etaType=ESTIMATED, timeValue=2019-04-12T15:05:36Z}]",
          "rvsmData" : "MapRecord[{futureCompliance=true, equipped=true, currentCompliance=true}]",
          "departureFixAndTime" : "MapRecord[{fixName=WORMS, arrTime=2019-04-12T13:15:00Z}]",
          "nextEvent" : "MapRecord[{longitudeDecimal=-80.8368083, latitudeDecimal=34.1616639}]"
        }
      },
      "flightPlanAmendmentInformation" : null,
      "arrivalInformation" : null,
      "flightPlanInformation" : null
    }, {
      "trackInformation" : {
        "qualifiedAircraftId" : {
          "aircraftId" : "UAL817",
          "computerId" : {
            "facilityIdentifier" : "KZDC",
            "idNumber" : "18T"
          },
          "gufi" : "KH29739600",
          "igtd" : "2019-04-12T11:00:00Z",
          "departurePoint" : {
            "airport" : "KAUS"
          },
          "arrivalPoint" : {
            "airport" : "KEWR"
          }
        },
        "speed" : 486,
        "reportedAltitude" : {
          "assignedAltitude" : {
            "simpleAltitude" : "410C"
          }
        },
        "position" : {
          "latitude" : {
            "latitudeDMS" : "MapRecord[{seconds=54, minutes=47, degrees=37, direction=NORTH}]"
          },
          "longitude" : {
            "longitudeDMS" : "MapRecord[{seconds=05, minutes=51, degrees=080, direction=WEST}]"
          }
        },
        "timeAtPosition" : "2019-04-12T13:48:58Z",
        "ncsmTrackData" : {
          "eta" : "MapRecord[{etaType=ESTIMATED, timeValue=2019-04-12T14:46:21Z}]",
          "rvsmData" : "MapRecord[{futureCompliance=true, equipped=true, currentCompliance=true}]",
          "arrivalFixAndTime" : "MapRecord[{fixName=ARD, arrTime=2019-04-12T14:31:57Z}]",
          "departureFixAndTime" : "MapRecord[{fixName=ILEXY, arrTime=2019-04-12T12:03:06Z}]",
          "nextEvent" : "MapRecord[{longitudeDecimal=-80.76862798233492, latitudeDecimal=37.80398852749686}]"
        }
      },
      "flightPlanAmendmentInformation" : null,
      "arrivalInformation" : null,
      "flightPlanInformation" : null
    } ]
  }
} ]

What is the RouteOnContent configuration that will allow me to determine if $[0].fltdOutput.fltdMessage is an array?


I'm trying to setup a test flow that only performs SplitJSON if it is an array. Notice in the following, I have a failure out of SplitJSON because its handling a version of the file that isnt an array

107749-1555081748281.png


I believe that I have to use a regular expression (similar to ^\[\{ ) as suggested here. However I'm not sure how the regular expression would look for $[0].fltdOutput.fltdMessage


I think the following should work

107750-1555087832816.png


I've tested this regular expression online:

^\[{"fltdOutput":{"fltdMessage":\[

Yet NIFI complains

107851-1555087981991.png


The following shows that the regular expression is valid, and that there are two matches within the five test strings.

107844-1555088499022.png

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