magor
magor

Reputation: 709

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 ?

Upvotes: 0

Views: 2487

Answers (1)

Sdairs
Sdairs

Reputation: 2032

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.

Upvotes: 3

Related Questions