Support Questions

Find answers, ask questions, and share your expertise

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


Cy Jervis, Manager, Community Program
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.

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