<?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 Unable to return a scalar value for the expression from NIFI EvaluateJsonPath  processor in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/m-p/213677#M175601</link>
    <description>&lt;P&gt;I'm using nifi to process json using Apache NIFI. &lt;/P&gt;&lt;P&gt;This is the input json:&lt;/P&gt;&lt;P&gt;{"key": "C919", "cells": [["year","2017",1497999002676770]]}&lt;/P&gt;&lt;P&gt;I'm using the following jsonpath expression: &lt;/P&gt;&lt;P&gt;$.cells[?(@[0]=='year')][1]&lt;/P&gt;&lt;P&gt;And in evaluatejsonpath processor, I got the following error:&lt;/P&gt;&lt;P&gt;
EvaluateJsonPath[id=015c1006-dd8a-1d92-5eb2-9ed9822065f8] Unable to return a scalar value for the expression $['cells'][?][1] for FlowFile 69572. Evaluated value was [1999]. Transferring to failure.&lt;/P&gt;&lt;P&gt;But the return value is a scalar value here, It is 1999. And if I change the json expression to $.cells[?(@[0]=='year')][1][0]. It not allowed and throws error. &lt;/P&gt;&lt;PRE&gt;EvaluateJsonPath[id=015c1006-dd8a-1d92-5eb2-9ed9822065f8] EvaluateJsonPath[id=015c1006-dd8a-1d92-5eb2-9ed9822065f8] failed to process session due to com.jayway.jsonpath.InvalidPathException: Filter: [0] can only be applied to arrays. Current context is: 1999: com.jayway.jsonpath.InvalidPathException: Filter: [0] can only be applied to arrays. Current context is: 1999&lt;/PRE&gt;&lt;P&gt;Is it a bug in NIFI?&lt;/P&gt;</description>
    <pubDate>Wed, 21 Jun 2017 21:57:24 GMT</pubDate>
    <dc:creator>jinxuanwu2013</dc:creator>
    <dc:date>2017-06-21T21:57:24Z</dc:date>
    <item>
      <title>Unable to return a scalar value for the expression from NIFI EvaluateJsonPath  processor</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/m-p/213677#M175601</link>
      <description>&lt;P&gt;I'm using nifi to process json using Apache NIFI. &lt;/P&gt;&lt;P&gt;This is the input json:&lt;/P&gt;&lt;P&gt;{"key": "C919", "cells": [["year","2017",1497999002676770]]}&lt;/P&gt;&lt;P&gt;I'm using the following jsonpath expression: &lt;/P&gt;&lt;P&gt;$.cells[?(@[0]=='year')][1]&lt;/P&gt;&lt;P&gt;And in evaluatejsonpath processor, I got the following error:&lt;/P&gt;&lt;P&gt;
EvaluateJsonPath[id=015c1006-dd8a-1d92-5eb2-9ed9822065f8] Unable to return a scalar value for the expression $['cells'][?][1] for FlowFile 69572. Evaluated value was [1999]. Transferring to failure.&lt;/P&gt;&lt;P&gt;But the return value is a scalar value here, It is 1999. And if I change the json expression to $.cells[?(@[0]=='year')][1][0]. It not allowed and throws error. &lt;/P&gt;&lt;PRE&gt;EvaluateJsonPath[id=015c1006-dd8a-1d92-5eb2-9ed9822065f8] EvaluateJsonPath[id=015c1006-dd8a-1d92-5eb2-9ed9822065f8] failed to process session due to com.jayway.jsonpath.InvalidPathException: Filter: [0] can only be applied to arrays. Current context is: 1999: com.jayway.jsonpath.InvalidPathException: Filter: [0] can only be applied to arrays. Current context is: 1999&lt;/PRE&gt;&lt;P&gt;Is it a bug in NIFI?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 21:57:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/m-p/213677#M175601</guid>
      <dc:creator>jinxuanwu2013</dc:creator>
      <dc:date>2017-06-21T21:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to return a scalar value for the expression from NIFI EvaluateJsonPath  processor</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/m-p/213678#M175602</link>
      <description>&lt;P&gt;The answer in &lt;A target="_blank" href="https://stackoverflow.com/questions/23608050/getting-a-single-value-from-a-json-object-using-jsonpath"&gt;this StackOverflow post&lt;/A&gt; refers to documentation saying an array will be returned; this appears to be happening after the JSONPath is evaluated (which is why appending a [0] does not work). The post also implies the answer: in NiFi, you can choose "json" as the Return Type and "flowfile-attribute" as the Destination in EvaluateJsonPath (let's say your dynamic property has key "my.attr" and a value of your JSONPath expression above), then follow that processor with an UpdateAttribute processor, setting "my.attr" to the following:&lt;/P&gt;&lt;PRE&gt;${my.attr:jsonPath('$[0]')}&lt;/PRE&gt;&lt;P&gt;This will overwrite the original "my.attr" value by hoisting the value out of the array. If you need that value back in the content, you can follow this with a ReplaceText processor to replace the Entire Text with the value of "my.attr".&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 23:33:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Unable-to-return-a-scalar-value-for-the-expression-from-NIFI/m-p/213678#M175602</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-06-21T23:33:22Z</dc:date>
    </item>
  </channel>
</rss>

