Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NiFi JoltTransformJSON - Several Changes

avatar
Explorer

Hello,

I am working with the JoltTransformJSON processor, which I consider to be very powerful but complicated to use and there is not much documentation about it.

I have the following input JSON:

 

 

{
   "logTypeCode":"FIN",
   "eventNumber":"1",
   "eventTime":1568066703172,
   "eventInfo":{
      "eventId":"CREATE_DOMESTIC_STANDING_ORDER",
      "eventVersion":"1"
   },
   "operationInfo":{
      "operationId":"DOMESTIC_STANDING_ORDER"
   }
}

 

 

 

And my output JSON I need it to be the following:

 

 

 

{
   "body":{
      "logTypeCode":"END_OF_TESTING",
      "eventNumber":"1",
      "eventTime":1568066703172,
      "eventInfo":{
         "eventId":"CREATE_DOMESTIC_STANDING_ORDER",
         "eventVersion":"1"
      },
      "operationInfo":{
         "operationId":"DOMESTIC_STANDING_ORDER"
      }
   },
   "header":{
      "date":"${dateInPropertiesFlow}"
   },
   "customValue":{
      "logTypeCode":"END_OF_TESTING",
      "ENV":"${anotherPropertie}"
   }
}

 

 

 

 

basically, I want to group everything that comes to me inside the "body" field, then I need to create another field that is called "header", which contains a single field called "date" with the value of a property that comes to me by the flow, and finally I need a field that is called "customValue", where the value "logTypeCode" has to have the same value as the field that is in "body.logTypeCode".

I'm trying several ways in the application https://jolt-demo.appspot.com/#inception but I can't get it to work as I want, for now this is the closest I got....

 

 

 

 

[
  {
    "operation": "shift",
    "spec": {
      "*": "body.&"
    }
   },
  {
    "operation": "default",
    "spec": {
      "header": {
        "date": "${paramDate}"
      }
    }
  }
]

 

I've been doing a lot of tests, but I can't get the result I need... Help!

 

Thanks

2 REPLIES 2

avatar
Explorer

can anyone help me? 

 

Thanks

avatar
Contributor

Not sure if this issue persist.
Attached is one way, using only one-phase shift operation:
1. date and env are flow file attributes which should be predefined when debugging under the JOLTTransformJSON Advanced Mode.
2. When dealing with JOLT Spec, we can predefine some constant which starts with "#" for the unexist value scope "#<constant>", in that way we can then handle the rest match-and-shift work .

 

[ {
  "operation" : "shift",
  "spec" : {
    "logTypeCode" : {
      "FIN" : {
        "#END_OF_TESTING" : {
			"$":"body.&3",
			"#END_OF_TESTING":"customValue.logTypeCode"
        }
      }
    },
    "*" : "body.&",
    "#${date}" : "header.date",
    "#${env}" : {
      "$" : "customValue.ENV"
    }
  }
} ]

==============
      OR
==============

[ {
  "operation" : "shift",
  "spec" : {
    "logTypeCode" : {
      "FIN" : {
        "#END_OF_TESTING" : {
			"$":"body.logTypeCode",
			"#END_OF_TESTING":"customValue.logTypeCode"
        }
      }
    },
    "*" : "body.&",
    "#${date}" : "header.date",
    "#${env}" : {
      "$" : "customValue.ENV"
    }
  }
} ]

 

  

Hope this helps.
Thanks