Search code examples
jsonapache-nifijolt

NiFi use string manipulation function like padRight in JoltTransformJSON


Can we use string manipulation functions like below in JoltTransformJSON

${BIG:padRight(5, '@')}

Link: https://jolt-demo.appspot.com/#modify-stringFunctions Expected Output: BIG@@

Like we use

"small_toUpper": "=toUpper(@(1,small))",
  "BIG_toLower": "=toLower(@(1,BIG))",

I am trying but it's not giving any error, but not giving the desired result as well. What would be other alternative for this.

Input JSON:

{
  "x": [
    3,
    2,
    1,
    "go"
  ],
  "small": "small",
  "BIG": "BIG",
  "people": [
    {
      "firstName": "Bob",
      "lastName": "Smith",
      "address": {
        "state": null
      }
    },
    {
      "firstName": "Sterling",
      "lastName": "Archer"
    }
  ]
}

Spec:

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "y": "=join(',',@(1,x))",
      "z": "=join(' ',@(1,x))",
      "small_toUpper": "=toUpper(@(1,small))",
      "BIG_toLower": "=toLower(@(1,BIG))",
      "BIG_padding": "=padRight(@(5,BIG))"
    }
  }
]

Solution

  • You can use rightPad function along with modify-xXx-beta (xXx:default or overwrite) transformation such as

    [
      {
        "operation": "modify-default-beta",
        "spec": {
          "BIG_padding": "=rightPad(@(1,BIG),5,'@')"
        }
      }
    ]
    

    enter image description here