1

I'm a newbie on Apache Nifi and have the following Problem: I would like to transform a json file as follows: From:

{
    "Property1": "x1",
    "Property2": "Tag_**2ABC**",
    "Property3": "x3",
    "Property4": "x4"
    }

to:

{
    "**2ABC**_Property1": "x1",
    "**2ABC**_Property3": "x3",
    "**2ABC**_Property4": "x4"
    },

it means: taking the value from a certain Attribute to update all other attributes. I could find examples using JoltTransformer-Processor that works well when the update is only adding a string. But not for my case What I've done so far: I have set each Attribute using evaluateJSONPath processor. But I just tried quite a lot of possibilities to use the update Attribute processor to do it without success. All my possible tests looked like (within UpdateAttribute):

Property1 --> ${'Property2':substring(4,6)}"_"${'Property1'}

Using Jolt:

[
{"operation": "modify-overwrite-beta",
    "spec": {
        "Property1": "${'Property2':substring(4,6)}_${'Property1'}"
            }
}
]

Which point am I missing here? Thanks in advance!

MDS
  • 13
  • 3

1 Answers1

3

I don't know about Nifi, but here is how you can do it in Jolt.

Spec

[
  {
    "operation": "shift",
    "spec": {
      // match Property2
      "Property2": {
        "Tag_*": { // capture the nasty "**2ABC**" part to reference later
          // go back up the tree to the root
          "@2": {
            // match and ignore Property2
            "Property2": null,
            //
            // match Property* and use it and the captured 
            //  "prefix" to create the output key
            //  &(2,1) references the Tag_*, and pull off the "**2ABC**" part
            "Property*": "&(2,1)_&"
          }
        }
      }
    }
  }
]
Milo S
  • 4,466
  • 1
  • 19
  • 22
  • Excellent thank you! Hopefully the OP will accept: NiFi accepts all the Jolt specs, just have to choose "Shift" then paste in Milo's spec :) – mattyb Sep 22 '17 at 01:44