Raii
Raii

Reputation: 303

Nifi Jolt Transform Spec

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

{
"response": {
"Attribute": [
  {
    "id": "670868",
    "another_id": "8385",
    "category": "A",
    "type": "abc"
  },
  {
    "id": "670870",
    "another_id": "8385",
    "category": "B",
    "type": "abc"
  }
]
}
}

My Jolt Spec is

enter code here 
[
{
"operation": "shift",
"spec": {
  "response": {
    "Attribute": {
      "*": {
        "type": "TYPE",
        "category": "CATEGORY"
      }
    }
  }
}
}
]

Current Output is

{
  "TYPE" : [ "abc", "abc" ],
  "CATEGORY" : [ "A", "B" ]
}

Wanted output is

[
   {
      "TYPE":"abc",
      "CATEGORY":"A"
   },
   {
      "TYPE":"abc",
      "CATEGORY":"B"
   }
]

Help please. I tried so many combinations and I can't seem to figure this out.

Upvotes: 1

Views: 1366

Answers (2)

Oussama Abouzid
Oussama Abouzid

Reputation: 184

[
  {
    "operation": "shift",
    "spec": {
      "response" : {
        "Attribute" : {
          "*" : {
            "type" : "[&1].TYPE",
            "category" : "[&1].CATEGORY"
          }
        }
      }
    }
  }
]

Upvotes: 0

Michał Ziober
Michał Ziober

Reputation: 38645

See Map to List example and you will find out solution:

[
  {
    "operation": "shift",
    "spec": {
      "response": {
        "Attribute": {
          "*": {
            "@type": "[#2].TYPE",
            "@category": "[#2].CATEGORY"
          }
        }
      }
    }
}
]

Upvotes: 1

Related Questions