Skip to main content
Apoo
Silver ⭐️⭐️
September 14, 2021
Question

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

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

Apoo
ApooAuthor
Silver ⭐️⭐️
October 4, 2021

can someone assist for the same

Translate
cjervis
Community Manager
Community Manager
October 20, 2021

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

Translate
Keep the questions coming
MattWho
Titanium ⭐️⭐️⭐️
Titanium ⭐️⭐️⭐️
October 20, 2021

@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

 

Translate
Apoo
ApooAuthor
Silver ⭐️⭐️
October 26, 2021

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

 

Translate
MattWho
Titanium ⭐️⭐️⭐️
Titanium ⭐️⭐️⭐️
October 27, 2021

@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

Translate