<?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: Problem in  JSON result with QueryCassandra processor in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109611#M46597</link>
    <description>&lt;P&gt;QueryCassandra does not support user-defined types, and instead will convert the values to strings. As a workaround, you can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt; to parse the strings into values. Here is an example Groovy script to accomplish this:&lt;/P&gt;&lt;PRE&gt;import groovy.json.*

def flowFile = session.get()
if(!flowFile) return
def directReport = flowFile.getAttribute('direct_report')
def json = new JsonSlurper().setType(JsonParserType.LAX).parseText(directReport)
json*.key.each { key -&amp;gt; 
  flowFile = session.putAttribute(flowFile, key,  json[key])
}
session.provenanceReporter.modifyAttributes(flowFile)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;&lt;P&gt;This script assumes you have used something like EvaluateJsonPath to extract $.results[0].directReports[0] into an attribute named 'direct_report'. It parses the JSON object and adds attributes to the flow file for each key/value pair in the object. You can adjust this to work with content rather than attributes, e.g. I have examples of various scripts on &lt;A target="_blank" href="http://funnifi.blogspot.com/"&gt;my blog&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Nov 2016 21:13:59 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2016-11-18T21:13:59Z</dc:date>
    <item>
      <title>Problem in  JSON result with QueryCassandra processor</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109610#M46596</link>
      <description>&lt;P&gt;Hello All, 
While working with the QueryCassandra processor, the resultant JSON does not look fine for user defined types. Is there any workaround for this? 
 
For the below &lt;/P&gt;&lt;PRE&gt;CREATE TYPE first.fullname (
  firstname text,
  lastname text
);
&lt;/PRE&gt;
&lt;PRE&gt;CREATE TABLE first.users (
  id uuid PRIMARY KEY,
  name frozen &amp;lt;fullname&amp;gt;,
  direct_reports set&amp;lt;frozen &amp;lt;fullname&amp;gt;&amp;gt;  
); &lt;/PRE&gt;&lt;PRE&gt;INSERT INTO first.users JSON '{
    "id" : "62c36092-82a1-3a00-93d1-46196ee77204",
    "name": {
        "firstname": "person4",
        "lastname": "4"
    },
    "direct_reports": [
        {
            "firstname": "person1",
            "lastname": "1"
        },
        {
            "firstname": "person2",
            "lastname": "2"
        },
        {
            "firstname": "person3",
            "lastname": "3"
        }
    ] 
}';&lt;/PRE&gt;&lt;P&gt;The resultant JSON has all the User defined types converted to a single string as in the attached screen capture. &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="9576-ss.png" style="width: 2740px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/23364iA4C7C98D2090AD7F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="9576-ss.png" alt="9576-ss.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Result for an Evaluate JSON Path expression results[0].direct_reports[0].firstname was directed to unmatched since the JSON result was not matching the expected JSON format. &lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://community.cloudera.com/t5/image/serverpage/image-id/7837iC3BADDC4484C141D/image-size/large?v=1.0&amp;amp;px=999" border="0" alt="ss.png" title="ss.png" /&gt;</description>
      <pubDate>Mon, 19 Aug 2019 11:33:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109610#M46596</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2019-08-19T11:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in  JSON result with QueryCassandra processor</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109611#M46597</link>
      <description>&lt;P&gt;QueryCassandra does not support user-defined types, and instead will convert the values to strings. As a workaround, you can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt; to parse the strings into values. Here is an example Groovy script to accomplish this:&lt;/P&gt;&lt;PRE&gt;import groovy.json.*

def flowFile = session.get()
if(!flowFile) return
def directReport = flowFile.getAttribute('direct_report')
def json = new JsonSlurper().setType(JsonParserType.LAX).parseText(directReport)
json*.key.each { key -&amp;gt; 
  flowFile = session.putAttribute(flowFile, key,  json[key])
}
session.provenanceReporter.modifyAttributes(flowFile)
session.transfer(flowFile, REL_SUCCESS)&lt;/PRE&gt;&lt;P&gt;This script assumes you have used something like EvaluateJsonPath to extract $.results[0].directReports[0] into an attribute named 'direct_report'. It parses the JSON object and adds attributes to the flow file for each key/value pair in the object. You can adjust this to work with content rather than attributes, e.g. I have examples of various scripts on &lt;A target="_blank" href="http://funnifi.blogspot.com/"&gt;my blog&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 21:13:59 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109611#M46597</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-11-18T21:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in  JSON result with QueryCassandra processor</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109612#M46598</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;. Currently I am handling this using a Javascript, similar approach to what you described. I wanted to confirm there is no other way. For simpler structures, I managed to extract the key values using Regex, but for deep nested keys, I was forced to use ExecuteScript. &lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 21:19:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Problem-in-JSON-result-with-QueryCassandra-processor/m-p/109612#M46598</guid>
      <dc:creator>arunak</dc:creator>
      <dc:date>2016-11-18T21:19:42Z</dc:date>
    </item>
  </channel>
</rss>

