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

查看:46
本文介绍了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天全站免登陆