Nifi - Remove zeros(00) of my json in Nifi

Good Night.

I need to remove the zeros of "numero":

{
  "cnpjemitente" : "48791685000168",
  "numero" : "001262851",
  "chavenfe" : "35221148791685000168550030012628511100259840",
  "serie" : "3  "
} 

The correct column:

{
  "cnpjemitente" : "48791685000168",
  "numero" : "1262851",
  "chavenfe" : "35221148791685000168550030012628511100259840",
  "serie" : "3  "
} 

I need the leading zeros to be removed whenever possible.

Can anyone help me? Thanks

Upvotes: 0

Views: 125

Answers (1)

Barbaros Özhan
Barbaros Özhan

Reputation: 65323

You can consecutively use the following within a JoltTransformJSON processor ;

  • toInteger and toString functions in a modify-overwrite-beta transformation spec

  • and then remove transformation in order to get rid of the auxiliary attribute "numero_"

such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "numero_": "=toInteger(@(1,numero))",// converts to 1262851(leading zeroes removed)
      "numero": "=toString(@(1,numero_))"// converts to "1262851"(quoted)
    }
  },
  {
    "operation": "remove",
    "spec": {
      "numero_": ""
    }
  }
]

or use

  • toInteger and toString functions in each individual consecutive modify-overwrite-beta transformation spec

such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "numero": "=toInteger"// converts to 1262851
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "numero": "=toString"// converts to "1262851"
    }
  }
]

Upvotes: 1

Related Questions