Support Questions

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

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

avatar
New Contributor

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
Super 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
New Contributor

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

avatar
Super 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
New Contributor

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

 

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

avatar
Super Mentor

@Wisdomstar 

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

Matt