具有多个输入的 Apache Nifi EvaluateJsonPath
Apache Nifi EvaluateJsonPath with Multiple Inputs
我有 JSON 个对象通过 MQTT
从两个不同的输入进入 Nifi - 例如,假设一个来自顶部传感器,一个来自底部传感器。每个传感器都有自己的 MQTT 主题,因此我使用两个不同的 ConsumeMQTT 处理器将这些数据提取到我的 Nifi Flow 中。
JSON 顶部传感器的对象 是 {"Top_Data": "value"}
JSON 底部传感器的对象 是 {"Bottom_Data": "value"}
我目前正在使用两个单独的 EvaluateJsonPath 处理器将 Top_Data
或 Bottom_Data
的值存储在名为 sensorData 的属性中。
我如何使用某种 if/or 语句仅使用一个处理器为我可以从 MQTT 获得的两个 JSON 对象评估 JsonPath?基本上,我想要一个表达式 "If my JSON object has a property called Top_Data, use its value for the attribute sensorData, otherwise, use the value from the property Bottom_Data."
Example of my EvaluateJsonPath Processor
也许试试 JSONPath 表达式
$[Top_Data,Bottom_Data]
单曲EvaluateJSONPathProcessor
。
根据 https://goessner.net/articles/JsonPath/ 可以使用替代运算符 [,]
:
[,]
Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
我已经使用 http://jsonpath.com/ 测试了表达式,它应该可以工作。
如果有帮助,请告诉我们。
您可以尝试使用 EvaluateJsonPath
(属性 1: top: $['top']
, 属性 2: bottom: $['bottom']
) 提取它们,当然不要忘记将 Destination
设置为 flowfile-attribute
。
然后,转到UpdateAttribute
,设置属性 finalData
为${top:isEmpty():ifElse(${bottom}, ${top})}
。
如果EvaluateJsonPath
找不到完整的元素,那么它将把它设置为空字符串,所以你需要做的就是检查它们是否为空,如果是,设置最后一个数据与另一个相同。
我有 JSON 个对象通过 MQTT
从两个不同的输入进入 Nifi - 例如,假设一个来自顶部传感器,一个来自底部传感器。每个传感器都有自己的 MQTT 主题,因此我使用两个不同的 ConsumeMQTT 处理器将这些数据提取到我的 Nifi Flow 中。
JSON 顶部传感器的对象 是 {"Top_Data": "value"}
JSON 底部传感器的对象 是 {"Bottom_Data": "value"}
我目前正在使用两个单独的 EvaluateJsonPath 处理器将 Top_Data
或 Bottom_Data
的值存储在名为 sensorData 的属性中。
我如何使用某种 if/or 语句仅使用一个处理器为我可以从 MQTT 获得的两个 JSON 对象评估 JsonPath?基本上,我想要一个表达式 "If my JSON object has a property called Top_Data, use its value for the attribute sensorData, otherwise, use the value from the property Bottom_Data."
Example of my EvaluateJsonPath Processor
也许试试 JSONPath 表达式
$[Top_Data,Bottom_Data]
单曲EvaluateJSONPathProcessor
。
根据 https://goessner.net/articles/JsonPath/ 可以使用替代运算符 [,]
:
[,]
Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set.
我已经使用 http://jsonpath.com/ 测试了表达式,它应该可以工作。
如果有帮助,请告诉我们。
您可以尝试使用 EvaluateJsonPath
(属性 1: top: $['top']
, 属性 2: bottom: $['bottom']
) 提取它们,当然不要忘记将 Destination
设置为 flowfile-attribute
。
然后,转到UpdateAttribute
,设置属性 finalData
为${top:isEmpty():ifElse(${bottom}, ${top})}
。
如果EvaluateJsonPath
找不到完整的元素,那么它将把它设置为空字符串,所以你需要做的就是检查它们是否为空,如果是,设置最后一个数据与另一个相同。