Search code examples
jsonapache-nifijolt

Convert Integer to String in JSON, Nifi


I have the following input JSON :

{
  "a": "value1",
  "b": [
    {
      "X": 1234
    },
    {
      "X": 4567
    }
  ]
}

I want the integer values to be converted to a string. Basically add double quotes to the integer. Desired output is:

{
  "a": "value1",
  "b": [
    {
      "X": "1234" // want to add double quotes
    },
    {
      "X": "4567" // want to add double quotes
    }
  ]
}

How do I achieve this? Thanks in advance.


Solution

  • You can use modify-overwrite-beta transformation spec with toString function embedded such as

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "b": {
            "*": {
              "X": "=toString"
            }
          }
        }
      }
    ]