0
votes

I'm trying to use nifi jolttransformjson to transform my JSON. I'm playing around using this site http://jolt-demo.appspot.com/#modify-stringFunctions

I have a JSON

[
{
"INDICATOR_VALUE": "val1",
"TYPE": "A"
},
{
   "INDICATOR_VALUE": "val2",
"TYPE": "B"
}
]

My Jolt Spec is

[
  {
"operation": "shift",
"spec": {
  "*": {
    "TYPE": {
      "A": {
        "#AA": "TYPE",
        "@(2,INDICATOR_VALUE)": "INDICATOR_VALUE"
      },
      "B": {
        "#BB": "TYPE",
        "@(2,INDICATOR_VALUE)": "INDICATOR_VALUE"
      }
    }
  }
}
}
]

Current Output is

{
  "TYPE" : [ "AA", "BB" ],
  "INDICATOR_VALUE" : [ "val1", "val2" ]
}

Wanted output is

[
   {
  "TYPE":"AA",
  "INDICATOR_VALUE":"val1"
   },
   {
  "TYPE":"BB",
  "INDICATOR_VALUE":"val2"
 }
]

So basically, I just want to change Type A to AA, and type B to BB.

1

1 Answers

1
votes
[
    {
        "operation":"shift",
        "spec":{
            "*":{
                "TYPE":{
                    "A":{
                        "#AA":"[&3].TYPE"
                    },
                    "B":{
                        "#BB":"[&3].TYPE"
                    }
                },
                "INDICATOR_VALUE":"[&1].INDICATOR_VALUE"
            }
        }
    }
]