[
https://issues.apache.org/jira/browse/NIFI-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15295338#comment-15295338
]
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_r64142229
--- Diff: nifi-docs/src/main/asciidoc/expression-language-guide.adoc ---
@@ -1161,7 +1161,61 @@ Expressions will provide the following results:
|=======================================================================================
+[.function]
+=== jsonPath
+
+*Description*: [.description]#The `jsonPath` function generates a string
by evaluating the Subject as JSON and applying a JSON
+ path expression. An empty string is generated if the Subject does not
contain valid JSON, the _jsonPath_ is invalid, or the path
+ does not exist in the Subject. If the evaluation results in a scalar
value, the string representation of scalar value is
+ generated. Otherwise a string representation of the JSON result is
generated. A JSON array of length 1 is special cased
+ when `[0]` is a scalar, the string representation of `[0]` is
generated.^1^#
+
+*Subject Type*: [.subject]#String#
+
+*Arguments*:
+ [.argName]#_jsonPath_# : [.argDesc]#the JSON path expression used to
evaluate the Subject.#
+*Return Type*: [.returnType]#String#
+
+*Examples*: If the "myJson" attribute is
+
+..........
+{
+ "firstName": "John",
+ "lastName": "Smith",
+ "isAlive": true,
+ "age": 25,
+ "address": {
+ "streetAddress": "21 2nd Street",
+ "city": "New York",
+ "state": "NY",
+ "postalCode": "10021-3100"
+ },
+ "phoneNumbers": [
+ {
+ "type": "home",
+ "number": "212 555-1234"
+ },
+ {
+ "type": "office",
+ "number": "646 555-4567"
+ }
+ ],
+ "children": [],
+ "spouse": null
+}
+..........
+
+.jsonPath Examples
+|===================================================================
+| Expression | Value
+| `${myJson:jsonPath('$.firstName')}` | `John`
+| `${myJson:jsonPath('$.address.postalCode')}` | `10021-3100`
+| `${myJson:jsonPath('$.phoneNumbers[?(@.type=="home")].number')}`^1^ |
`212 555-1234`
+| `${myJson:jsonPath('$.phoneNumbers')}` | `[{"type":"home","number":"212
555-1234"},{"type":"office","number":"646 555-4567"}]`
+| `${myJson:jsonPath('$.missing-path')}` |
+| `${myJson:jsonPath('$.bad@expression')}` |
--- End diff --
For the bad JSON Paths (missing or invalid), perhaps it should explicitly
say the value is "_empty_" or something like that. I couldn't find other
examples of table entries where the values were empty, but I did see one where
a space was called out by _space_ to make it more explicit and visible.
> 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)