Support Questions

Find answers, ask questions, and share your expertise

how to replace the underscore "_" at the end of a dict key using NIFI?

avatar
Contributor

I revoked an HTTP request the response is a list of JSON records [{},{},{}] within those records we have some keys with an "_" at the end.


[ {

  "name":"json",

  "surname":"file",

  "which_extention_":"json",

  "size_of_file_":"266" }, {}, {} ]


It needs to look like that:

 

[ {

  "name":"json",

  "surname":"file",

  "which_extention":"json",

  "size_of_file":"266" }, {}, {} ]


I tried to use replacetext with the regex : [_$]$ and with this _$ but doesn't work.

2 REPLIES 2

avatar

@Ghilani I believe the solution here is to use record based processors with a JSON RECORD Reader with the schema matching _ names, and a JSON RECORD Writer with schema matching the new names.   

avatar
Master Mentor

@Ghilani 
While I agree that using record based processors so you can work with single FlowFiles with multiple records in them to make more efficient dataflows, what you are doing here should be possible with a ReplaceText processor in the interim using "Literal Replace":

MattWho_0-1651862888224.png

 

Here we are searching for the pattern _" and replacing it with just ".

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