<?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 transform a json array to a string list in NIFI in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/182230#M144396</link>
    <description>&lt;P&gt;As of NiFi 1.2.0 you may be able to use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.2.0/org.apache.nifi.processors.standard.ConvertRecord/index.html"&gt;ConvertRecord&lt;/A&gt; to do this, with a &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.2.0/org.apache.nifi.json.JsonTreeReader/index.html"&gt;JsonTreeReader&lt;/A&gt; and a &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.2.0/org.apache.nifi.csv.CSVRecordSetWriter/index.html"&gt;CSVRecordSetWriter&lt;/A&gt; (with a Record separator of comma and a value separator of a single space).&lt;/P&gt;&lt;P&gt;Prior to 1.2.0 (or if the above approach doesn't work), you can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-scripting-nar/1.2.0/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt;. Here is a sample Groovy script that will read all the "term" values from the incoming JSON object and add an attribute called "terms" containing the comma-separated list:&lt;/P&gt;&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return
def input = session.read(flowFile)
def json = new groovy.json.JsonSlurper().parse(input)
def terms = json.results.collect { it.term }.join(',')
input.close()
flowFile = session.putAttribute(flowFile, 'terms', terms)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;&lt;P&gt;If instead you need to replace the content of the flow file with the comma-separated list:&lt;/P&gt;&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return
flowFile = session.write(flowFile, { inputStream, outputStream -&amp;gt;
  def json = new groovy.json.JsonSlurper().parse(inputStream)
  def terms = json.results.collect { it.term }.join(',')
  outputStream.write(terms.bytes)
} as StreamCallback)
flowFile = session.putAttribute(flowFile, 'mime.type', 'text/csv')
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 May 2017 20:42:33 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2017-05-24T20:42:33Z</dc:date>
    <item>
      <title>How to transform a json array to a string list in NIFI</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/182229#M144395</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;i have a queryCassandra which generate a json like this one:&lt;/P&gt;&lt;PRE&gt;{"results":[{"term":"term1"},{"term":"term2"}..]} &lt;/PRE&gt;&lt;P&gt;Now, i want to get from this all the terms values separated by some separator in string format; &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ex : term1,term2,term3 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So i can pass this list as a string parameter for a java main program which i've alreat set. &lt;/P&gt;&lt;P&gt;(i only need the transofrmation, not the java program execution) Thank you !&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2017 22:26:31 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/182229#M144395</guid>
      <dc:creator>adib_amine_mdr</dc:creator>
      <dc:date>2017-05-22T22:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a json array to a string list in NIFI</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/182230#M144396</link>
      <description>&lt;P&gt;As of NiFi 1.2.0 you may be able to use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.2.0/org.apache.nifi.processors.standard.ConvertRecord/index.html"&gt;ConvertRecord&lt;/A&gt; to do this, with a &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.2.0/org.apache.nifi.json.JsonTreeReader/index.html"&gt;JsonTreeReader&lt;/A&gt; and a &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.2.0/org.apache.nifi.csv.CSVRecordSetWriter/index.html"&gt;CSVRecordSetWriter&lt;/A&gt; (with a Record separator of comma and a value separator of a single space).&lt;/P&gt;&lt;P&gt;Prior to 1.2.0 (or if the above approach doesn't work), you can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-scripting-nar/1.2.0/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt;. Here is a sample Groovy script that will read all the "term" values from the incoming JSON object and add an attribute called "terms" containing the comma-separated list:&lt;/P&gt;&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return
def input = session.read(flowFile)
def json = new groovy.json.JsonSlurper().parse(input)
def terms = json.results.collect { it.term }.join(',')
input.close()
flowFile = session.putAttribute(flowFile, 'terms', terms)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;&lt;P&gt;If instead you need to replace the content of the flow file with the comma-separated list:&lt;/P&gt;&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return
flowFile = session.write(flowFile, { inputStream, outputStream -&amp;gt;
  def json = new groovy.json.JsonSlurper().parse(inputStream)
  def terms = json.results.collect { it.term }.join(',')
  outputStream.write(terms.bytes)
} as StreamCallback)
flowFile = session.putAttribute(flowFile, 'mime.type', 'text/csv')
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 May 2017 20:42:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/182230#M144396</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-05-24T20:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to transform a json array to a string list in NIFI</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/401407#M251143</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;SPAN&gt;mburgess! This was helpful.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 10:39:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-transform-a-json-array-to-a-string-list-in-NIFI/m-p/401407#M251143</guid>
      <dc:creator>SS_Jin</dc:creator>
      <dc:date>2025-02-03T10:39:10Z</dc:date>
    </item>
  </channel>
</rss>

