Nifi:如何更改json的值? [英] nifi: how to change value of json?

查看:682
本文介绍了Nifi:如何更改json的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有处理器InvokeHTTP,它提供json结果. 例如:

i have processor InvokeHTTP which gives json result. for instance:

{
  "revision" : {
    "clientId" : "dc572274-4b71-11b6-e415-b91e391bcf4d",
    "version" : 7
  },
  "id" : "dc572260-4b71-11b6-0371-f73573ab44fe",
  "uri" : "http://x.x.x.x:9090/nifi-api/processors/dc572260-4b71-0371-73ab44fe",
  "position" : {
    "x" : -1021.9568138214972,
    "y" : 333.2029958718132
  }
}

我想为InvokeHTTP的每个传入响应动态更改version的值. 如何做到这一点?

i want to change the value of version dynamically for each incoming response of InvokeHTTP. how to achieve this?

推荐答案

您可以使用以下处理器序列:EvaluateJsonPath获取属性的值,UpdateAttribute对其进行更改,以及ReplaceText替换中的旧值使用正则表达式来满足新内容的需求.

you can use this sequence of processors: EvaluateJsonPath to get value of attribute, UpdateAttribute to change it, and ReplaceText to substitute old value in content with new one using regular expression.

对于ReplaceText处理器,请使用以下参数:

For the ReplaceText processor use following parameters:

Regexp Replace策略

搜索值:(?s)("version"\s*:\s*)(\d+)

替换值:$1${VERSION}(其中VERSION是保存新值的属性名称)

Replacement Value : $1${VERSION} (where VERSION is an attribute name that holds new value)

这里是测试正则表达式的好资源: https://regex101.com/r/JOrZNp/1

Here is a nice resource to test the regular expressions: https://regex101.com/r/JOrZNp/1

这篇关于Nifi:如何更改json的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆