<?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: NiFi: trying to create record set from one field in and embedded array in JSON in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382878#M244729</link>
    <description>&lt;P&gt;My Pleasure . I'm glad you were able to get it with the help of Jolt. I agree jolt is a little intimidating initially, but with practice , trial and error you grow to love it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; . A simpler way to represent your spec:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "store": {
        "book": {
          "*": "[]"
        }
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;Feel free to post any jolt question or challenges in the future.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 14:12:58 GMT</pubDate>
    <dc:creator>SAMSAL</dc:creator>
    <dc:date>2024-01-30T14:12:58Z</dc:date>
    <item>
      <title>NiFi: trying to create record set from one field in and embedded array in JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382829#M244711</link>
      <description>&lt;P&gt;I have this JSON:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
  "store": {
    "book": [
      {
        "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      {
        "category": "fiction",
        "author": "Herman Melville",
        "title": "Moby **bleep**",
        "isbn": "0-553-21311-3",
        "price": 8.99
      },
      {
        "category": "fiction",
        "author": "J.R.R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;I&amp;nbsp;&lt;SPAN&gt;want a list/record set of categories. CSV, plain text, doesn't matter, but let's say CSV:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;category
"refereces"
"fiction"
"fiction"&lt;/LI-CODE&gt;&lt;P&gt;I have tried many things, too many to repeat them all here. But basically, I have a GenerateFlowFile where the JSON is hard-coded, then a QueryReport where the reader is a JsonPathReader where I have properties for all fields in the JSON:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;store     $.store
book      $.store.book[*]
category  $.store.book[*].category
etc.&lt;/LI-CODE&gt;&lt;P&gt;Just to see what's being returned, I currently have the writer set to an all-defaults JsonRecordSetWriter.&lt;/P&gt;&lt;P&gt;With this in mind, in the QueryRecord, select * returns the JSON unaltered. select store returns the JSON unaltered. select book returns "no column named 'book'". I can use an EvaluateJsonPath with $.store.book[*].category as the property value, and it returns this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;["references", "fiction", "fiction"]&lt;/LI-CODE&gt;&lt;P&gt;If I switch over to an all-defaults CSVRecordSetWriter and do select store, I get this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;store
MapRecord[{book=[Ljava.lang.Object;@24bda2f0}]&lt;/LI-CODE&gt;&lt;P&gt;I know there are other ways to configure EvaluateJsonPath so it does parse the data correctly, but in doing so, it creates a FlowFile for each record. I don't want that; I want a single recordset in one FlowFile because this is just a proof of concept. With the real data I'm looking at tens of thousands of records.&lt;/P&gt;&lt;P&gt;I also know I could take this to Groovy and get it done. I'd like to avoid that and only use to the bare minimum of native NiFi processors.&lt;/P&gt;&lt;P&gt;I've also tried some things with a ForkRecord, but as I said, I've kind of lost the bubble on everything I've tried. I believe this is possible but running out of energy and ideas and think I've exhausted the wisdom of the web. Is it really this difficult?&lt;/P&gt;&lt;P&gt;Let me know what I'm doing wrong.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 15:24:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382829#M244711</guid>
      <dc:creator>noncitizen</dc:creator>
      <dc:date>2024-01-29T15:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: trying to create record set from one field in and embedded array in JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382866#M244722</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/104397"&gt;@noncitizen&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;I think using&amp;nbsp; JsonPathReader is not the right choice for this requirement. This service according to the documentation will always evaluate against the root element:&lt;/P&gt;&lt;P&gt;".&lt;EM&gt;..If the root of the FlowFile's JSON is a JSON Array, each JSON Object found in that array will be treated as a separate Record, not as a single record made up of an array. If the root of the FlowFile's JSON is a JSON Object, it will be evaluated as a single Record...&lt;/EM&gt;"&lt;/P&gt;&lt;P&gt;ref: &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.23.2/org.apache.nifi.json.JsonPathReader/additionalDetails.html" target="_blank"&gt;https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.23.2/org.apache.nifi.json.JsonPathReader/additionalDetails.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;So since your root element "store" is an object it will always return a single record , and if it happens that one of the fields is an array , it will be returned as a single record as an array representation:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;["references", "fiction", "fiction"]&lt;/LI-CODE&gt;&lt;P&gt;It seems the JsonPathReader is more suited when your root element is an array. If you want to make it work so that it returns multiple records you probably need to do jolt transformation to dump all book array items into root array. Keep in mind if you want just the category or any other certain field you have to define an Avro schema with the expected fields otherwise all none specified fields will be returned with blank values.&lt;/P&gt;&lt;P&gt;What you need is JsonTreeReader service instead where its configured to use Nested Field as Starting Field Strategy, then specify "book" as the Starting Field Name, as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_0-1706609795720.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/39610iA8ECB3D8D40D1F59/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_0-1706609795720.png" alt="SAMSAL_0-1706609795720.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The QueryRecord then simply can be configured as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAMSAL_1-1706609912610.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/39611i97190EA248022733/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAMSAL_1-1706609912610.png" alt="SAMSAL_1-1706609912610.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;which will give you desired output in CSV format:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;category
reference
fiction
fiction&lt;/LI-CODE&gt;&lt;P&gt;If that helps please &lt;STRONG&gt;accept&lt;/STRONG&gt; solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 10:26:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382866#M244722</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-01-30T10:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: trying to create record set from one field in and embedded array in JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382870#M244724</link>
      <description>&lt;P&gt;Wow, I was excited when I saw this as it looked like the kind of simple elegance I was looking for, and I wondered why I hadn't noticed the Starting Field Strategy property, because in trying to work this out, I had previously turned to JsonTreeReader. But in implementing it, I see why. We're on version 11.9.0, and the JsonTreeReader is version 1.14.0.i, meaning, I don't have those capabilities.&lt;/P&gt;&lt;P&gt;Because moving to a more recent version is not possible, I will go down the JOLT pathway and see what I can work out. Even though I couldn't test it out, I will accept your solution because I believe if I had the latest and greatest, it would be the one. Plus, your description of the JSON hierarchy in play here was helpful.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 10:50:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382870#M244724</guid>
      <dc:creator>noncitizen</dc:creator>
      <dc:date>2024-01-30T10:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: trying to create record set from one field in and embedded array in JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382873#M244726</link>
      <description>&lt;P&gt;UPDATE: I'm working on an enclave, so this initial test was at&amp;nbsp;jolt-demo.appspot.com, but moving it over to NiFi, I had to add one addition level in the JOLT transformation. What appears below is now correct.&lt;/P&gt;&lt;P&gt;That was quick. This JOLT transformation . . .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*":
            {
              "@": ""
            }
          }
        }
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;. . . transform the JSON to this . . .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ {
  "category" : "reference",
  "author" : "Nigel Rees",
  "title" : "Sayings of the Century",
  "price" : 8.95
}, {
  "category" : "fiction",
  "author" : "Herman Melville",
  "title" : "Moby **bleep**",
  "isbn" : "0-553-21311-3",
  "price" : 8.99
}, {
  "category" : "fiction",
  "author" : "J.R.R. Tolkien",
  "title" : "The Lord of the Rings",
  "isbn" : "0-395-19395-8",
  "price" : 22.99
} ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And with an all-defaults JSONTreeReader and CSVRecordSetWriter, "select category" returns exactly what I need. I was thinking about JOLT, but haven't done much with it, and was fearful of the complexity. So thanks again,&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt; for pushing me in the right direction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 11:42:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382873#M244726</guid>
      <dc:creator>noncitizen</dc:creator>
      <dc:date>2024-01-30T11:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi: trying to create record set from one field in and embedded array in JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382878#M244729</link>
      <description>&lt;P&gt;My Pleasure . I'm glad you were able to get it with the help of Jolt. I agree jolt is a little intimidating initially, but with practice , trial and error you grow to love it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; . A simpler way to represent your spec:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "store": {
        "book": {
          "*": "[]"
        }
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;Feel free to post any jolt question or challenges in the future.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 14:12:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-trying-to-create-record-set-from-one-field-in-and/m-p/382878#M244729</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-01-30T14:12:58Z</dc:date>
    </item>
  </channel>
</rss>

