Apache NiFi RecordPath Guide
Also available as:
PDF

Maps

Similar to an Array field, a Map field may actually consist of several different values. RecordPath gives us the ability to select a set of values based on their keys. We do this by using a quoted String within square brackets. As an example, let's re-visit our original Record from above:

{
        "name": "John Doe",
        "details": {
                "identifier": 100,
                "address": {
                        "number": "123",
                        "street": "5th Avenue",
                        "city": "New York",
                        "state": "NY",
                        "zip": "10020"
                }
        }
}

Now, though, let's consider that the Schema that is associated with the Record indicates that the address field is not a Record but rather a Map field. In this case, if we attempt to reference the zip using the RecordPath /details/address/zip the RecordPath will not match because the address field is not a Record and therefore does not have any Child Record named zip. Instead, it is a Map field with keys and values of type String. Unfortunately, when looking at JSON this may seem a bit confusing because JSON does not truly have a Type system. When we convert the JSON into a Record object in order to operate on the data, though, this distinction can be important.

In the case laid out above, we can still access the zip field using RecordPath. We must now use the a slightly different syntax, though: /details/address['zip']. This is telling the RecordPath that we want to access the details field at the highest level. We then want to access its address field. Since the address field is a Map field we can use square brackets to indicate that we want to specify a Map Key, and we can then specify the key in quotes.

Further, we can select more than one Map Key, using a comma-separated list: /details/address['city', 'state', 'zip']. We can also select all of the fields, if we want, using the Wildcard operator (): /details/address[]. Map fields do not contain any sort of ordering, so it is not possible to reference the keys by numeric indices.