Skip to main content
Wisdomstar
Silver ⭐️⭐️
January 18, 2022
Solved

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

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.

MattWho
MattWhoAnswer
Titanium ⭐️⭐️⭐️
January 18, 2022

@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

5 replies

m_adeel
Gold ⭐️
January 18, 2022

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.nifi.processors.standard.ExecuteStreamCommand/index.html

Translate
Wisdomstar
Silver ⭐️⭐️
January 19, 2022

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

Translate
MattWho
Titanium ⭐️⭐️⭐️
MattWhoAnswer
Titanium ⭐️⭐️⭐️
January 18, 2022

@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

Translate
Wisdomstar
Silver ⭐️⭐️
January 19, 2022

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

 

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

Translate
MattWho
Titanium ⭐️⭐️⭐️
Titanium ⭐️⭐️⭐️
January 19, 2022

@Wisdomstar 

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

Matt

Translate