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!

Unable to extract a special character nested dictionary dynamic key in json

avatar
New Contributor

hi i have a following json nested dictionary:

{"data" :{
"Abc_def_{x_y.z.test_at_here}.json":{
"timestamp_start": 0,

"timestamp_stop": 0

}

}}

i need to extract the value of 3rd level json key that is from timestamps :

{

"timestamp_start": 0,

"timestamp_stop": 0

}

I tried using evauatejsonpath with $.data.['Abc_def_{x_y.z.test_at_here}.json']. it worked fine.

But i have the content inside curly {x_y.z.test_at_here} in .json key which is dynamic with special characters.

Also tried parsing usin updateattribute, but i am unable pass it as a string in eval

5 REPLIES 5

avatar
New Contributor

can someone assist for the same

avatar
Community Manager

Sorry for the late reply. I'm not an expert but have you looked at this solved thread? Extract string nested in JSON value

Keep the questions coming

avatar
Master Mentor

@Apoo 

Not sure if this is the best solution, but you could use a combination of EvaluateJsonPath and ReplaceText to convert you sample source in to you sample output.

 EvaluateJsonPath processor:

MattWho_0-1634752112935.png

'new"dynamic property (can use any property name) = $.data[*]

this would result in this output based on your example:

[{"timestamp_start":0,"timestamp_stop":0}]

 

So we can then use the replaceText to trim off the leading "[" and trailing "]":

MattWho_1-1634752238821.png

Search Value = (^\[)|(\]$)

Then you have you desired output of:

{"timestamp_start":0,"timestamp_stop":0}

 

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

this solution is already tried and it works like all matches. but i dont want to use data[*]. As my request is to parse a dict key which is dynamic and needs to be validated for a right string along with fetching the its values.. meaning the content inside data.['ABC_xyz'] which is a string how can we set it.. I dont understand how to pass a var ${} as string in data.[] bcoz key name also has some special chars

 

avatar
Master Mentor

@Apoo 

The EvaluateJsonPath processor dynamic properties do not support NiFi Expression language, so being able to pass dynamic strings to these dynamic properties from FlowFile attributes is not possible.   The dynamic properties only support NiFi parameters.

You may want to raise an Apache NiFi jira requesting adding NiFi EL support to these dynamic properties or even contribute the the open source code if you so choose.

Thank you,

Matt