Apache Nifi 仅删除 Json 中一个属性中的非字母数字字符
Apache Nifi Remove non-alphanumeric characters in only one attribute in Json
希望有人能帮助我。我正在尝试通过做一些项目来学习 Apache Nifi,其中我有 json 以下格式的文件:
{
"network": "reddit",
"posted": "2021-12-24 10:46:51 +00000",
"postid": "rnjv0z",
"title": "A gil commission artwork of my friends who are in-game couples!",
"text": "A gil commission artwork of my friends who are in-game couples! ",
"lang": "en",
"type": "status",
"sentiment": "neutral",
"image": "https://a.thumbs.redditmedia.com/ShKq9bu4_ZIo4k5QIBYotstmyGidRgn8046RcqPo_p0.jpg",
"url": "http://www.reddit.com/r/ffxiv/comments/rnjv0z/a_gil_commission_artwork_of_my_friends_who_are/",
"user": {
"userid": "Suhteeven",
"name": "Suhteeven",
"url": "http://www.reddit.com/user/Suhteeven"
},
"popularity": [
{
"name": "ups",
"count": 1
},
{
"name": "comments",
"count": 0
}
]
}
我想从“文本”属性中删除所有非字母数字字符。我只想修改这一个属性,而文件名的其余部分保持不变。
我尝试在添加文本属性的地方使用 EvaluateJsonPath 处理器。然后我创建了 ReplaceText 处理器。
此配置清除了文本中的特殊字符,但结果我只有文本属性的值。我不想丢失其他信息,我的目标是修改输出中所有属性的文本属性值。
我也尝试了 UpdateAttribute 处理器,但是这个处理器没有对我的 json 做任何事情(输出与输入相同)。
你能告诉我在什么配置下应该使用什么处理器吗?我尝试了很多不同的东西,但我被卡住了。
处理器可以实现 ScriptedTransformProcessor
记录Reader:JsonTreeReader
记录作者:JsonRecordSetWriter
脚本语言(默认):Groovy
脚本正文
record.setValue("text", attributes['text'])
record
数据流:EvaluateJsonPath(评估text
属性)->UpdateAttribute(修改text
属性)->ScriptedTransformProcessor(添加text
记录)
希望有人能帮助我。我正在尝试通过做一些项目来学习 Apache Nifi,其中我有 json 以下格式的文件:
{
"network": "reddit",
"posted": "2021-12-24 10:46:51 +00000",
"postid": "rnjv0z",
"title": "A gil commission artwork of my friends who are in-game couples!",
"text": "A gil commission artwork of my friends who are in-game couples! ",
"lang": "en",
"type": "status",
"sentiment": "neutral",
"image": "https://a.thumbs.redditmedia.com/ShKq9bu4_ZIo4k5QIBYotstmyGidRgn8046RcqPo_p0.jpg",
"url": "http://www.reddit.com/r/ffxiv/comments/rnjv0z/a_gil_commission_artwork_of_my_friends_who_are/",
"user": {
"userid": "Suhteeven",
"name": "Suhteeven",
"url": "http://www.reddit.com/user/Suhteeven"
},
"popularity": [
{
"name": "ups",
"count": 1
},
{
"name": "comments",
"count": 0
}
]
}
我想从“文本”属性中删除所有非字母数字字符。我只想修改这一个属性,而文件名的其余部分保持不变。
我尝试在添加文本属性的地方使用 EvaluateJsonPath 处理器。然后我创建了 ReplaceText 处理器。
此配置清除了文本中的特殊字符,但结果我只有文本属性的值。我不想丢失其他信息,我的目标是修改输出中所有属性的文本属性值。
我也尝试了 UpdateAttribute 处理器,但是这个处理器没有对我的 json 做任何事情(输出与输入相同)。
你能告诉我在什么配置下应该使用什么处理器吗?我尝试了很多不同的东西,但我被卡住了。
处理器可以实现 ScriptedTransformProcessor
记录Reader:
JsonTreeReader
记录作者:
JsonRecordSetWriter
脚本语言(默认):
Groovy
脚本正文
record.setValue("text", attributes['text'])
record
数据流:EvaluateJsonPath(评估text
属性)->UpdateAttribute(修改text
属性)->ScriptedTransformProcessor(添加text
记录)