【问题标题】:jsonPath Expression for json and json of json parameter using NIFI expression LangaugejsonPath Expression for json 和 json 参数的 json 使用 NIFI 表达式语言
【发布时间】:2020-04-23 05:40:56
【问题描述】:

我有如下的 json,

{
    "name1" : "Aks",
    "address1": {
      "area" : "area1",
      "location1": "loc1"

    },
    "phonenum": "1445452"
}

我需要从 address1 中检索所有键,并且只需要 location1 参数。

我试过了, $.*, $.['address1'].location1 在 JsonPath 表达式中,但没有成功,对此有什么提示吗?

【问题讨论】:

  • 请解释清楚.. 是否需要将name1phonenumaddress1.location1 提取到它们自己的属性中?
  • 是的,你是对的。

标签: json apache-nifi json-path-expression


【解决方案1】:

@aksy91 您需要使用 EvaluateJsonPath 处理器进行映射:

name1: $.name1

location1: $.address1.location1

phonenum: $.phonenum 

请务必将第一个值设置为 flowfile-attribute。

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.11.0/org.apache.nifi.processors.standard.EvaluateJsonPath/index.html

【讨论】:

  • 是的,成功了!谢谢,需要进一步澄清,可以使用 PutDatabaseRecord 处理器将此流文件属性插入本地数据库表吗?我的发现,ExecuteSQL-->ConvertAvroToJson-->EvaluateJson-->PutDatabaseRecord。但是在 PutDatabaseRecord --> 中选择 JSONTreeRecord 作为 RecordReader 和 AvroSchemaRegistry 作为它的 SchemaAccessStrategy。我有oracle DB,我使用'username'作为'schema.name',它无法插入,错误无法处理standardflowfilerecord nifi putdatabaserecord..请提供任何建议..
【解决方案2】:

好吧,你需要做的是添加三个新的动态属性:

name1:$.name1

location1:$.address1.location1

phonenum: $.phonenum

【讨论】:

  • 在同一个 jsonPath 表达式中?表达式 Path 中应使用任何分隔符?示例:$.name1,$.address1.location1,$.phonenum
  • 按原样输入,attribute_name:attribute_value。当然,Destination 也应该设置为flowfile-attribute。请告诉我它是否适合你
  • 如你所说使用过,但没有运气..我哪里出错了,无法理解
  • 请在您的问题中添加完整的详细信息,包括您尝试执行的操作的屏幕截图,我也会添加我所做的操作的屏幕截图
  • 我有这样的结构,ExecuteSQL --> ConverAvroToJson --> UpdateAttribute --> SplitJson 所以在SplitJson中我给出如下的jsonPath表达式 name1: $.name1 location1: $.address1.location1 phonenum : $.phonenum 我做对了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-03
  • 2019-06-06
  • 2022-01-03
  • 1970-01-01
  • 2021-12-02
  • 2023-03-26
  • 2017-02-05
相关资源
最近更新 更多