- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to count the number of records of a JSON object flow file in NiFi?
- Labels:
-
Apache NiFi
Created ‎06-18-2019 02:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am calling an API which returns a JSON object as the body of the response as a flow file. I want to count the total records in the flow file.
I tried record processors like CalculateRecordStats needs a record reader and that in-turn needs a schema. But I don't have a schema. So Is there a better way to do it?
{
"result":[
{
"key1": "value1",
"key2": "value2"
},
{
"key1": "value1",
"key2": "value2"
}
]
}
This is the sample JSON the api response body returns. The records are the items of the list which is the value of the "result" key
In the above sample there are 2 records (2 items in the list). So that is what I want to calculate.
Created on ‎06-18-2019 02:30 AM - edited ‎08-17-2019 02:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One aproach may be to use the "EvaluateJsonPath" Processor as following to get the total number of results (basically result is an Array here) so we can try something like following to store the size of the array to a new attribute
resultCount = $.result.length()
Example:
Then later you can read the attribute resultCount in some other processor as following: ${resultCount}
.
Created on ‎06-18-2019 02:30 AM - edited ‎08-17-2019 02:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One aproach may be to use the "EvaluateJsonPath" Processor as following to get the total number of results (basically result is an Array here) so we can try something like following to store the size of the array to a new attribute
resultCount = $.result.length()
Example:
Then later you can read the attribute resultCount in some other processor as following: ${resultCount}
.
