Created 09-13-2021 11:53 PM
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
Created 10-03-2021 11:46 PM
can someone assist for the same
Created 10-20-2021 06:50 AM
Sorry for the late reply. I'm not an expert but have you looked at this solved thread? Extract string nested in JSON value
Created 10-20-2021 10:53 AM
@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:
'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 "]":
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
Created on 10-26-2021 04:56 AM - edited 10-26-2021 04:58 AM
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
Created 10-27-2021 02:20 PM
@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