需要有关从 Apache NiFi 中的流文件检索 JSON 属性的帮助

Need help on retrieving JSON attributes from a flow file in Apache NiFi

我正在尝试使用 NiFi 中的 EvaluvateJsonPath 处理器从 JSON 文件中获取属性值。

下面是示例 JSON 文件

{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}

下面是我的配置。

预期的输出应该是 "main_window"。但是我得到了整个 JSON 字符串作为输出。有人能给我指出正确的方向吗,这里出了什么问题?

更新:

这是流文件内容,我在队列中看到它是 EvaluvateJsonPath 处理器的结果。

"Name"-->$.widget.window.name 正确。

但是你必须指定"ReturnType"-->json不是"ReturnType"-->autodetect

这就是问题所在,因为您收到了整个 json 字符串。

EDIT-1

如果您将 return 类型更改为 json,那么您可以收到预期的输出 "main_window"` 以存储在属性 ${Name}.

之后您可以使用 ReplaceText 处理器指定替换值 "${Name}" 然后您可以接收 "main_window" 在流文件中

它对我有用。

如果您遇到任何问题,请告诉我