Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Rename JSON field in NiFi flow

I'm fairly new to NiFi, my question might be basic. I would like to rename the JSON key in the flowfile. For example:

{"path":"/home/a/a", "size":"12345"}

and I would like to convert to

{"filename":"/home/a/a", "size":"12345"}

Tried using UpdateAttribute, adding a filename attribute with the value ${path} but either I'm doing something wrong or it's not meant to be used for this kind of operation.

How could I rename the attribute in a JSON ?

question from:https://stackoverflow.com/questions/65901012/rename-json-field-in-nifi-flow

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is the content of your FlowFile, not an Attribute, so UpdateAttribute is not the right way to go.

The easiest way with JSON content of FlowFiles is going to be via a JOLTTransform.

Give this spec a try:

[
  {
    "operation": "shift",
    "spec": {
      "path": "filename",
      "*": {
        "@": "&"
      }
    }
  }
]

You can test JOLT transforms here with input data and see what the output will be.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...