[ 
https://issues.apache.org/jira/browse/NIFI-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15295336#comment-15295336
 ] 

ASF GitHub Bot commented on NIFI-1660:
--------------------------------------

Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/303#discussion_r64142194
  
    --- Diff: 
nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java
 ---
    @@ -233,6 +233,24 @@ public void testEmbeddedExpressionsAndQuotes() {
         }
     
         @Test
    +    public void testJsonPath() {
    +        final Map<String, String> attributes = new HashMap<>();
    +        attributes.put("json",
    +                "{" + "\n  \"firstName\": \"John\"," + "\n  \"lastName\": 
\"Smith\"," + "\n  \"isAlive\": true," + "\n  \"age\": 25," + "\n  \"address\": 
{"
    +                        + "\n    \"streetAddress\": \"21 2nd Street\"," + 
"\n    \"city\": \"New York\"," + "\n    \"state\": \"NY\","
    +                        + "\n    \"postalCode\": \"10021-3100\"" + "\n  
}," + "\n  \"phoneNumbers\": [" + "\n    {" + "\n      \"type\": \"home\","
    +                        + "\n      \"number\": \"212 555-1234\"" + "\n    
}," + "\n    {" + "\n      \"type\": \"office\","
    +                        + "\n      \"number\": \"646 555-4567\"" + "\n    
}" + "\n  ]," + "\n  \"children\": []," + "\n  \"spouse\": null" + "\n}");
    +        verifyEquals("${json:jsonPath('$.firstName')}", attributes, 
"John");
    +        verifyEquals("${json:jsonPath('$.address.postalCode')}", 
attributes, "10021-3100");
    +        
verifyEquals("${json:jsonPath(\"$.phoneNumbers[?(@.type=='home')].number\")}", 
attributes, "212 555-1234");
    +        verifyEquals("${json:jsonPath('$.phoneNumbers')}", attributes,
    +                "[{\"type\":\"home\",\"number\":\"212 
555-1234\"},{\"type\":\"office\",\"number\":\"646 555-4567\"}]");
    +        verifyEquals("${json:jsonPath('$.missing-path')}", attributes, "");
    +        verifyEquals("${missing:jsonPath('$.bad@expression')}", 
attributes, "");
    +    }
    --- End diff --
    
    Perhaps add a test for an existing attribute containing invalid JSON.  If 
the behavior on bad JSON is changed to throw an exception (see above comment), 
a test could verify that; otherwise it should be tested for null.


> Enhance the expression language with jsonPath function
> ------------------------------------------------------
>
>                 Key: NIFI-1660
>                 URL: https://issues.apache.org/jira/browse/NIFI-1660
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Core Framework
>    Affects Versions: 0.5.1
>            Reporter: Christopher McDermott
>            Assignee: Joseph Witt
>            Priority: Minor
>             Fix For: 1.0.0, 0.7.0
>
>
> jsonPath would evaluate a JSON path provided, as an argument, against the 
> subject.
> Example
> {quote}
> $\{kafka.key:jsonPath('$.foo.bar')\}
> {quote}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to