EvaluateJsonPath 无法 return 标量

EvaluateJsonPath unable to return a scalar

我正在尝试从 JSON 中提取一个值到 flowfile-attribute。当我 运行 EvaluateJsonPath 处理器时,我收到一条错误消息

"Unable to get a scalar value for expression $..fields.storyBoard.stringValue

输入 JSON 看起来像这样:

{
  "name" : "projects/fakedims-0000/databases/(default)/documents/device/0000",
  "fields" : {
    "reportKey" : {
      "stringValue" : "abc123"
    },
    "dateOccured" : {
      "timestampValue" : "2018-10-14T04:00:00Z"
    },
    "storyBoard" : {
      "stringValue" : "https://path/to/media"
    },
    "new" : {
      "integerValue" : "25"
    },
    "name" : {
      "stringValue" : "device one"
    },
    "location" : {
      "geoPointValue" : {
        "latitude" : -78.413751,
        "longitude" : 38.156487
      }
    }
  },
  "createTime" : "2018-10-19T00:02:26.209335Z",
  "updateTime" : "2018-10-19T22:22:24.382136Z"
}

JSON路径表达式是$..fields.storyBoard.stringValue

我认为正在发生的事情是处理器正在返回 ["https://path/to/media"] 而不仅仅是字符串。

如果对流文件内容而不是属性求值,这就是我得到的结果。为什么?我能做些什么来修复它?

Return 类型 属性 值更改为 json in EvaluateJsonPath 处理器,如果您正在提取为流文件属性

Return类型属性描述:

Indicates the desired return type of the JSON Path expressions. Selecting 'auto-detect' will set the return type to 'json' for a Destination of 'flowfile-content', and 'scalar' for a Destination of 'flowfile-attribute'.

当您尝试提取嵌套密钥而不是根级别的密钥(例如:name、createTime..)时,这就是我们需要将 Return 类型配置为 [=48= 的原因] 不像 标量.

此外,您可以使用 FlattenJson 处理器(分隔符 '_') 来展平所有嵌套 json 然后使用 Return Type as auto detect评估Json路径处理器中。

评估Json配置:

输出: 我们将拥有不包含在数组中的属性值