<?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 read json from S3 then edit json using Nifi in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346179#M234790</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11191"&gt;@araujo&lt;/a&gt;&amp;nbsp;, Right now there is no error in Nifi flow. But when I tried to execute a copy command (from an SQL query editor) on the file, it gave me an error "Invalid JSONPath format: Member is not an object. ". When I searched about this error, I found this -&amp;nbsp;&lt;A href="https://stackoverflow.com/a/45348425" target="_blank" rel="noopener nofollow noreferrer"&gt;https://stackoverflow.com/a/45348425&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is why I wanted to convert the file.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 01:16:03 GMT</pubDate>
    <dc:creator>baymax277</dc:creator>
    <dc:date>2022-06-23T01:16:03Z</dc:date>
    <item>
      <title>How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346142#M234772</link>
      <description>&lt;P&gt;I am using Nifi 1.6.0. I am trying to copy an S3 file into redshift. The json file on S3&amp;nbsp; looks like this:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;[&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{"a":1,"b":2},&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{"a":3,"b":4}&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;]&lt;/FONT&gt;&lt;BR /&gt;However this gives an error because of '[' and ']' in the file (&lt;A href="https://stackoverflow.com/a/45348425" target="_blank" rel="noopener"&gt;https://stackoverflow.com/a/45348425&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;I need to convert the json from above format to a format which looks like this:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{"a":1,"b":2}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;{"a":3,"b":4}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;So basically what I am trying to do is to remove '[' and ']' and replace '},' with '}'.&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;The file has over 14 million rows (30 MB in size)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;How can I achieve this using Nifi?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 00:48:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346142#M234772</guid>
      <dc:creator>baymax277</dc:creator>
      <dc:date>2022-06-23T00:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346173#M234785</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98740"&gt;@baymax277&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem with your file is &lt;STRONG&gt;not&lt;/STRONG&gt; the square brackets (&lt;STRONG&gt;[ ]&lt;/STRONG&gt;). The issue is that single quotes are not a valid JSON quote. The correct JSON would be:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
{"a":1,"b":2},
{"a":3,"b":4}
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The content above is processed correctly by NiFi if you use record-based processors (like, for example Query&lt;STRONG&gt;Record&lt;/STRONG&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally your source data should be fixed to provide a valid JSON. For example, if those files are being generated by a Python script like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;my_object = [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}]
print(my_object)&lt;/LI-CODE&gt;&lt;P&gt;The Python script should be updated to do this instead:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import json
my_object = [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}]
print(json.dumps(my_object))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you cannot have the source data fixed, you can try to replace the single quotes with double quotes using a ReplaceText processor with the following configuration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="araujo_0-1655941522722.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34664i35BC0527FAF39333/image-size/medium?v=v2&amp;amp;px=400" role="button" title="araujo_0-1655941522722.png" alt="araujo_0-1655941522722.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a simplistic approach, though, and can cause problems in some complex JSON objects if you have strings with unexpected sequences of characters in them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 23:46:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346173#M234785</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-06-22T23:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346174#M234786</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98740"&gt;@baymax277&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you share a screenshot of the part of you flow that reads and processes the JSON content?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 00:51:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346174#M234786</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-06-23T00:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346175#M234787</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11191"&gt;@araujo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Sorry, my bad. I made a mistake in the json representation mentioned in the question. The records actually have double quotes ("). I have updated the question.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 00:52:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346175#M234787</guid>
      <dc:creator>baymax277</dc:creator>
      <dc:date>2022-06-23T00:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346177#M234788</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11191"&gt;@araujo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;The jsons files are compressed and are placed in an S3 bucket. Here's the flow I have created to fetch s3 file and decompress it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="baymax277_0-1655945817170.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34665i67B82C8790981959/image-size/medium?v=v2&amp;amp;px=400" role="button" title="baymax277_0-1655945817170.png" alt="baymax277_0-1655945817170.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 00:57:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346177#M234788</guid>
      <dc:creator>baymax277</dc:creator>
      <dc:date>2022-06-23T00:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346178#M234789</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98740"&gt;@baymax277&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you also share the screenshot of the part of the flow where the error is happening? I think that's after the Decompress File step, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 01:01:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346178#M234789</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-06-23T01:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346179#M234790</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11191"&gt;@araujo&lt;/a&gt;&amp;nbsp;, Right now there is no error in Nifi flow. But when I tried to execute a copy command (from an SQL query editor) on the file, it gave me an error "Invalid JSONPath format: Member is not an object. ". When I searched about this error, I found this -&amp;nbsp;&lt;A href="https://stackoverflow.com/a/45348425" target="_blank" rel="noopener nofollow noreferrer"&gt;https://stackoverflow.com/a/45348425&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is why I wanted to convert the file.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 01:16:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346179#M234790</guid>
      <dc:creator>baymax277</dc:creator>
      <dc:date>2022-06-23T01:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346180#M234791</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98740"&gt;@baymax277&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok. Can you share a screenshot of the part of the flow that insert the data into your database?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 01:18:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346180#M234791</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-06-23T01:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346186#M234793</link>
      <description>&lt;P&gt;I have not created that part of the flow yet, but that will be an ExecuteStreamCommand processor which will run a psql command with the copy sql query:&lt;BR /&gt;It will look something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="baymax277_0-1655948726669.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34666i7F2B356C01DE73D3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="baymax277_0-1655948726669.png" alt="baymax277_0-1655948726669.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 01:45:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346186#M234793</guid>
      <dc:creator>baymax277</dc:creator>
      <dc:date>2022-06-23T01:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346187#M234794</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98740"&gt;@baymax277&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should look into using&amp;nbsp;PutDatabaseRecord instead of ExecuteStreamCommand. This would be more efficient and it would eliminate the need to manually remove those brackets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 01:49:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346187#M234794</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-06-23T01:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346188#M234795</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/11191"&gt;@araujo&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try this solution, but I think the&amp;nbsp;queue to&amp;nbsp;&lt;SPAN&gt;PutDatabaseRecord&amp;nbsp;processor will get clogged very soon because there are over 14 million rows in this file.&lt;BR /&gt;&lt;BR /&gt;I tried Replace text and I was able to replace '},' to '}' within seconds. Can you tell me how to remove the first line '[' and the last line ']'?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 01:57:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346188#M234795</guid>
      <dc:creator>baymax277</dc:creator>
      <dc:date>2022-06-23T01:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to read json from S3 then edit json using Nifi</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346193#M234796</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/98740"&gt;@baymax277&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="araujo_0-1655951401398.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/34667i20EBF8535623A3A6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="araujo_0-1655951401398.png" alt="araujo_0-1655951401398.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is the regex:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(?s)(^\[|\]$)&lt;/LI-CODE&gt;&lt;P&gt;You may have to increase the buffer size to accommodate your file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;André&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 02:32:03 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-read-json-from-S3-then-edit-json-using-Nifi/m-p/346193#M234796</guid>
      <dc:creator>araujo</dc:creator>
      <dc:date>2022-06-23T02:32:03Z</dc:date>
    </item>
  </channel>
</rss>

