<?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 - JSON to MongoDB - problems with array in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286583#M212530</link>
    <description>&lt;P&gt;Thank you for the input, this was helpful advice!&lt;/P&gt;</description>
    <pubDate>Mon, 30 Dec 2019 13:53:38 GMT</pubDate>
    <dc:creator>AV_1010</dc:creator>
    <dc:date>2019-12-30T13:53:38Z</dc:date>
    <item>
      <title>NiFi - JSON to MongoDB - problems with array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286497#M212470</link>
      <description>&lt;P&gt;I am a new NiFi and MongoDB user. I'm attempting to create an ingest process that first accepts a JSON file that will provide the information about a project (project submission id, project name, project submittor, project attachments (array of documents). I am able to parse the JSON information until I get to the array of project attachments. The project attachments field is an array with the name of one or more project documents (ex: attachment1.docx, attachment2.ppt, etc). The end goal is to put each project submission in MongoDB as a document. The project attachments field must be an array so I can reference them later when parsing the metadata from each of the attachment files. I want to be able to nest the metadata for each attachment to correspond to each attachment file in the array.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far, I am the problem I am running into is that the final project attachments array somehow becomes a string instead of an array after passing through the AttributesToJSON processor. I can see that the JSON looks fine until it gets to this processor then after AttributesToJSON, suddenly there are quotes around the array like this:&amp;nbsp;"file_attachment" : "[\"attachment1.docx\",\"attachment2.docx\",\"attachment3.docx\",\"attachment4.docx\"]"&lt;/P&gt;
&lt;P&gt;Because of this, the PutMongoRecord processor enters the array in MongoDB as a string instead of array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using the following processors:&lt;/P&gt;
&lt;P&gt;GetFile - read in&amp;nbsp; json file&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SplitJson&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EvaluateJsonPath - destination = flowfile-attribute, return type=json, renaming some json fields as they are converted to flowfile attributes (submission id = $.id, abstract = $.abstract, file_attachment = $.data.[*] &amp;lt;---COULD this be part of the problem?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: after passing through this processor, file_attachment shows up like this in the attributes:&amp;nbsp;&lt;/P&gt;
&lt;DIV class="attribute-name"&gt;["attachment1.docx","attachment2.docx","attachment3.docx","attachment4.docx"]"&lt;/DIV&gt;
&lt;DIV class="attribute-name"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;AttributesToJSON - specify the flowfile attributes to write to flowfile content. When viewing the flow-file content the fields have converted correctly EXCEPT for tile attachment:&lt;/P&gt;
&lt;P&gt;"file_attachment" : "[\"attachment1.docx\",\"attachment2.docx\",\"attachment3.docx\",\"attachment4.docx\"]"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea how to get around this issue? Thank you for any suggestions!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2019 02:28:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286497#M212470</guid>
      <dc:creator>AV_1010</dc:creator>
      <dc:date>2019-12-28T02:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - JSON to MongoDB - problems with array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286510#M212480</link>
      <description>&lt;P&gt;The first thing that comes to mind is not select $.data.* but something like&amp;nbsp;$.data.file_attachment or&amp;nbsp;$.data.file_attachment.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this bring you (closer) to the answer?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there are still simple things you want to change in the text, you could use this workaround:&lt;/P&gt;&lt;P&gt;In the update Attribute processor use something like replaceall.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps, but also curious if there are other things relevant here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2019 10:15:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286510#M212480</guid>
      <dc:creator>DennisJaheruddi</dc:creator>
      <dc:date>2019-12-28T10:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - JSON to MongoDB - problems with array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286540#M212502</link>
      <description>&lt;P&gt;Regarding:&lt;/P&gt;&lt;PRE&gt;"file_attachment" : "[\"attachment1.docx\",\"attachment2.docx\",\"attachment3.docx\",\"attachment4.docx\"]"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The processor translates the object as a string. &amp;nbsp;You will need to take some action on it to prepare it as you want it to be downstream. &amp;nbsp;Assuming you are working with content of FlowFile, the processor you need is ReplaceText and the syntax is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;${'$1':unescapeJson()}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To dial it even further so its not a string at all:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;${'$1':unescapeJson():replace('"[','['):replace(']"',']')}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is same in the ReplaceText processor properties:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-12-29 at 9.51.48 AM.png" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/25866iEBB843B08E427C94/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-12-29 at 9.51.48 AM.png" alt="Screen Shot 2019-12-29 at 9.51.48 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are operating on an attribute, you can do the similar action with UpdateAttribute:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;${attributeName:unescapeJson()}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this reply answers your question please mark it as a Solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2019 14:56:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286540#M212502</guid>
      <dc:creator>stevenmatison</dc:creator>
      <dc:date>2019-12-29T14:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - JSON to MongoDB - problems with array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286582#M212529</link>
      <description>&lt;P&gt;Thank you, this worked perfectly!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 13:51:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286582#M212529</guid>
      <dc:creator>AV_1010</dc:creator>
      <dc:date>2019-12-30T13:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - JSON to MongoDB - problems with array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286583#M212530</link>
      <description>&lt;P&gt;Thank you for the input, this was helpful advice!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 13:53:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-JSON-to-MongoDB-problems-with-array/m-p/286583#M212530</guid>
      <dc:creator>AV_1010</dc:creator>
      <dc:date>2019-12-30T13:53:38Z</dc:date>
    </item>
  </channel>
</rss>

