Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

How to lower case all JSON attributes in a flow file using Apache Nifi

avatar
Frequent Visitor

I have a JSON text coming in a flowfile. 

{
      "_id":{
         "_data":"8261DB7CD7000000362B022C0100296E5A1004B9491C697A7B45E1BCDF455EB59ABC6F46645F6964006461DB7CD7564AB600124193730004"
      },
      "operationType":"insert",
      "clusterTime":{
         "$timestamp":{
            "t":1641774295,
            "i":54
         }
      }
}

 

I would like to be able to replace all JSON attribute names with lowercased names.

Nifi is quite new to me. Can anyone please give a sample implementation?

Thank you very much.

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Wisdomstar 

 

You should be able to use the JoltTransformJson NiFi processor to accomplish this.

MattWho_0-1642521884514.png

 

There is a thread here where a jolt specification example exists fro doing what you are trying to do:
https://stackoverflow.com/questions/54696540/jolt-transformation-lowercase-all-keys

 

Add the Jolt specification in to the "Jolt Specification" property in the JoltTransformJson NiFi processor.  Set "Pretty Print" to true if you still want the nice multi-line formatted json to be produced.

If you found this response assisted with your query, please take a moment to login and click on "Accept as Solution" below this post.

Thank you,

Matt

View solution in original post

5 REPLIES 5

avatar
Explorer

You can do this by using ExecuteStreamCommand processor. In that processor you will give a python script path. While in script you can get this data, perform your desired operation and let the data out. Link to documentation is
https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.5.0/org.apache...

avatar
Frequent Visitor

Many thanks for your guidance. I will take a look.

avatar
Master Mentor

@Wisdomstar 

 

You should be able to use the JoltTransformJson NiFi processor to accomplish this.

MattWho_0-1642521884514.png

 

There is a thread here where a jolt specification example exists fro doing what you are trying to do:
https://stackoverflow.com/questions/54696540/jolt-transformation-lowercase-all-keys

 

Add the Jolt specification in to the "Jolt Specification" property in the JoltTransformJson NiFi processor.  Set "Pretty Print" to true if you still want the nice multi-line formatted json to be produced.

If you found this response assisted with your query, please take a moment to login and click on "Accept as Solution" below this post.

Thank you,

Matt

avatar
Frequent Visitor

Many thanks for your guidance. I will take a look.

 

PS. Your numerous solutions in the past had helped me a lot.

avatar
Master Mentor

@Wisdomstar 

Thank you, I appreciate that and glad I could help.

Matt