<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to count the number of records of a JSON object flow file in NiFi? in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-count-the-number-of-records-of-a-JSON-object-flow/m-p/242687#M204486</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/114801/sandeepgunda.html" nodeid="114801" target="_blank"&gt;@Sandeep Gunda&lt;/A&gt;&lt;/P&gt;&lt;P&gt;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 &lt;/P&gt;&lt;PRE&gt;resultCount = $.result.length()&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="109404-json-array-count.png" style="width: 1628px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/13565i8D673313AFF7572F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="109404-json-array-count.png" alt="109404-json-array-count.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Then later you can read the attribute resultCount in some other processor as following:  &lt;STRONG&gt; ${resultCount}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;</description>
    <pubDate>Sat, 17 Aug 2019 21:55:38 GMT</pubDate>
    <dc:creator>jsensharma</dc:creator>
    <dc:date>2019-08-17T21:55:38Z</dc:date>
    <item>
      <title>How to count the number of records of a JSON object flow file in NiFi?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-count-the-number-of-records-of-a-JSON-object-flow/m-p/242686#M204485</link>
      <description>&lt;DIV&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;{
"result":[
    {
        "key1": "value1",
        "key2": "value2"
    },
    {
        "key1": "value1",
        "key2": "value2"
    }
]
}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;In the above sample there are 2 records (2 items in the list). So that is what I want to calculate.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer noopener noreferrer" href="https://stackoverflow.com/questions/56640685/how-to-count-the-number-of-records-of-a-json-object-flow-file-in-nifi" target="_blank"&gt;You can also answer here&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 18 Jun 2019 09:22:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-count-the-number-of-records-of-a-JSON-object-flow/m-p/242686#M204485</guid>
      <dc:creator>sandeep_gunda</dc:creator>
      <dc:date>2019-06-18T09:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of records of a JSON object flow file in NiFi?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-count-the-number-of-records-of-a-JSON-object-flow/m-p/242687#M204486</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/114801/sandeepgunda.html" nodeid="114801" target="_blank"&gt;@Sandeep Gunda&lt;/A&gt;&lt;/P&gt;&lt;P&gt;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 &lt;/P&gt;&lt;PRE&gt;resultCount = $.result.length()&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="109404-json-array-count.png" style="width: 1628px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/13565i8D673313AFF7572F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="109404-json-array-count.png" alt="109404-json-array-count.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Then later you can read the attribute resultCount in some other processor as following:  &lt;STRONG&gt; ${resultCount}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 21:55:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-count-the-number-of-records-of-a-JSON-object-flow/m-p/242687#M204486</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2019-08-17T21:55:38Z</dc:date>
    </item>
  </channel>
</rss>

