<?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 JoltJsonTransform spec help needed in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199398#M81186</link>
    <description>&lt;P&gt;sorry for my  ignorance. I could resolve this issue by removing one additional space in " list" while wring the flowfile content generated by groovy script. Now I am able to fetch the data from invoke http by passing flowfile content from executescript.&lt;/P&gt;&lt;P&gt;Thanks for the support.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vish&lt;/P&gt;</description>
    <pubDate>Fri, 27 Jul 2018 20:40:36 GMT</pubDate>
    <dc:creator>vishhs</dc:creator>
    <dc:date>2018-07-27T20:40:36Z</dc:date>
    <item>
      <title>Nifi JoltJsonTransform spec help needed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199394#M81182</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Need help in JoltJSONTransform spec that can be used to convert the input to output.&lt;/P&gt;&lt;P&gt;I have tried to use map to List and other syntax, but was not been successful so far. Any help is appreciated.&lt;/P&gt;&lt;P&gt;Input:&lt;/P&gt;&lt;P&gt;{"params":"sn=GH6747246T4JLR6AZ&amp;amp;c=QUERY_RECORD&amp;amp;p=test_station_name&amp;amp;p=station_id&amp;amp;p=result&amp;amp;p=mac_addresss"}&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;{   "queryType": "scan",   "dataSource": "xyz",   "resultFormat": "list",   "columns":["test_station_name","station_id","result","mac_address"],   "intervals": [     "2018-01-01/2018-02-09"   ],"filter": { "type": "selector", "dimension": "sn", "value":"GH6747246T4JLR6AZ"  } }&lt;/P&gt;&lt;P&gt;Except for the content inside Columns and dimension and value attributes rest of the fields are hardcoded.&lt;/P&gt;&lt;P&gt;Please suggest.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vish&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:31:02 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199394#M81182</guid>
      <dc:creator>vishhs</dc:creator>
      <dc:date>2022-09-16T13:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi JoltJsonTransform spec help needed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199395#M81183</link>
      <description>&lt;P&gt;AFAIK, Jolt doesn't have functions for doing transformations of a single value (such as split, extract, etc.). If the "params" field will always contain the same parameters in the same order (at least sn being first, c being second, and 4 p's) then you can extract "params" into an attribute using EvaluateJsonPath (with a JSONPath of $.params), then an update attribute with something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="83446-updateattribute-parse.png" style="width: 665px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/17648i32D24FD1D4F3336F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="83446-updateattribute-parse.png" alt="83446-updateattribute-parse.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If the parameters are arbitrary (such as number of p's, or can be in any order), you might be better off with ExecuteScript for your custom logic. Here's a Groovy script you can use in ExecuteScript to do what you describe above:&lt;/P&gt;&lt;PRE&gt;import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets
import groovy.json.*
def flowFile = session.get()
if(!flowFile) return
flowFile = session.write(flowFile,
    { inputStream, outputStream -&amp;gt;
        def text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
        def obj = new JsonSlurper().parseText(text)
def params = obj.params.tokenize('&amp;amp;')
        def builder = new groovy.json.JsonBuilder()
        builder.call {
            'queryType' 'scan'
    'dataSource' 'xyz'
    'resultFormat' ' list'
            'columns' params.findAll {p -&amp;gt; p.tokenize('=')[0] == 'p'}.collect {p -&amp;gt; p.tokenize('=')[1]}
    'intervals' ([] &amp;lt;&amp;lt;  '2018-01-01/2018-02-09')
    'filter' { 
'type' 'selector'
   'dimension' 'sn'
'value' params.find {p -&amp;gt; p.tokenize('=')[0] == 'sn'}.tokenize('=')[1]
    }
        }
        outputStream.write(builder.toPrettyString().getBytes(StandardCharsets.UTF_8))
    } as StreamCallback)
flowFile = session.putAttribute(flowFile, "filename", flowFile.getAttribute('filename').tokenize('.')[0]+'_translated.json')
session.transfer(flowFile, ExecuteScript.REL_SUCCESS)&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Aug 2019 05:55:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199395#M81183</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2019-08-18T05:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi JoltJsonTransform spec help needed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199396#M81184</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/641/mburgess.html" nodeid="641"&gt;@Matt Burgess&lt;/A&gt; for the help. I could use the script that you shared. Number of parameters are dynamic in nature. Now I could see the content in output as below:&lt;/P&gt;&lt;P&gt;{
    "queryType": "scan",
    "dataSource": "nifi_kafka_druid_test",
    "resultFormat": " list",
    "columns": [
        "test_station_name",
        "station_id",
        "result",
        "mac_addresss"
    ],
    "intervals": [
        "2018-01-01/2018-02-09"
    ],
    "filter": {
        "type": "selector",
        "dimension": "sn",
        "value": "GH6747246T4JLR6AZ"
    }
}&lt;/P&gt;&lt;P&gt;Now I am trying to pass this to invokehttp to my druid broker endpoint url. But I am not able to get the response back from invokehttp.&lt;/P&gt;&lt;P&gt;Here if I use curl command: &lt;/P&gt;&lt;P&gt;curl -X POST 'brokerip:port/druid/v2/?pretty' -H 'Content-Type:application/json' -d'{   "queryType": "scan",   "dataSource": "nifi_kafka_druid_test",   "resultFormat": "list",   "columns":["station_id","mac_address","result","test_station_name"],   "intervals": [     "2018-01-01/2018-02-09"   ],"filter": { "type": "selector", "dimension": "sn", "value":"GGJ807405ZBJLR6AB"  } }'&lt;/P&gt;&lt;P&gt;I get the response:&lt;/P&gt;&lt;P&gt;
[ {
  "segmentId" : "nifi_kafka_druid_test_2018-02-07T00:00:00.000Z_2018-02-07T00:05:00.000Z_2018-07-17T13:27:30.419Z",
  "columns" : [ "station_id", "mac_address", "result", "test_station_name" ],
  "events" : [ {
    "station_id" : "LMMP_IQE-1FT-01_42_AE-1",
    "mac_address" : "ABC",
    "result" : "PASS",
    "test_station_name" : "EPI_DIE"
  } ]&lt;/P&gt;&lt;P&gt;I want to perform the same based on the flowfile content produced by executescript. &lt;/P&gt;&lt;P&gt;Am I missing some thing? how should I pass the data content to invokehttp processor?&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vish&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 17:22:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199396#M81184</guid>
      <dc:creator>vishhs</dc:creator>
      <dc:date>2018-07-27T17:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi JoltJsonTransform spec help needed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199397#M81185</link>
      <description>&lt;P&gt;In addition to my earlier query, I could call druid endpoint to fetch the data based on the flow file content holding the json record.&lt;/P&gt;&lt;P&gt;flowfilecontent--&amp;gt;&amp;gt;replacetext--&amp;gt;updateattribute--&amp;gt;&amp;gt;Invokehttp--&amp;gt;putfile&lt;/P&gt;&lt;P&gt;in replace text I gave replacement value as below:&lt;/P&gt;&lt;P&gt;{"queryType":"scan","dataSource":"nifi_kafka_druid_test","resultFormat":"list","columns":["station_id","mac_address","result","test_station_name"],"intervals":["2018-01-01/2018-02-09"],"filter":{"type":"selector","dimension":"sn","value":"GGJ807405ZBJLR6AB"}}&lt;/P&gt;&lt;P&gt;and added the attribute mime.type=application/json in update attribute&lt;/P&gt;&lt;P&gt;I can call the invokehttp to druid end point to fetch the data by endpoint url:&lt;/P&gt;&lt;P&gt;[{"segmentId":"nifi_kafka_druid_test_2018-02-07T00:00:00.000Z_2018-02-07T00:05:00.000Z_2018-07-17T13:27:30.419Z","columns":["station_id","mac_address","result","test_station_name"],"events":[{"station_id":"LMMP_IQE-1FT-01_42_AE-1","mac_address":"ABC","result":"PASS","test_station_name":"EPI_DIE"}]}]&lt;/P&gt;&lt;P&gt;But when I try to pass flow file content of the groovy script to invokehttp I am not getting any response.&lt;/P&gt;&lt;P&gt;I also changed the groovy script to write the content of the json in single line instead of multiline pretty format.&lt;/P&gt;&lt;P&gt;Looking through the data provenance of the sample pipeline mentioned above to the actual pipeline with the execute script, I do not see any difference in the flowfile content passed to invokehttp. Not sure, what am I doing wrong.&lt;/P&gt;&lt;P&gt;Please suggest.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vish&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 19:34:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199397#M81185</guid>
      <dc:creator>vishhs</dc:creator>
      <dc:date>2018-07-27T19:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Nifi JoltJsonTransform spec help needed</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199398#M81186</link>
      <description>&lt;P&gt;sorry for my  ignorance. I could resolve this issue by removing one additional space in " list" while wring the flowfile content generated by groovy script. Now I am able to fetch the data from invoke http by passing flowfile content from executescript.&lt;/P&gt;&lt;P&gt;Thanks for the support.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Vish&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jul 2018 20:40:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Nifi-JoltJsonTransform-spec-help-needed/m-p/199398#M81186</guid>
      <dc:creator>vishhs</dc:creator>
      <dc:date>2018-07-27T20:40:36Z</dc:date>
    </item>
  </channel>
</rss>

