Created on 01-28-2020 03:43 AM - last edited on 01-28-2020 04:26 AM by ask_bill_brooks
HI,
I have an attribute of type string and my flow file has an array of strings. I want to add attribute into the array of strings in flow file.
Please help me with the process.
Thank you
Created 01-28-2020 03:52 AM
For me your question is to abstract, sorry. Could you show some of your data?
Are we talking about JSON-array?
If so and you are already using NiFi 1.10.0 there are some new options in expression language to manipulate JSON.
Created 01-28-2020 04:16 AM
This is my JSON in flow file content
{
"linkedData" : [ ],
"comid" : "C3XXXXXXXXXXA-aidan-16802451"
}
I have an attribute
Created 01-28-2020 11:11 AM
Maybe you want to try this way. Worked on 1.10.0
Created 01-28-2020 11:45 PM
Thank so much for the reply.
I tried the flow, but i am see an exception "Unexpected token 'jsonPathAdd'". I am using nifi 2.11.
org.apache.nifi.processor.exception.ProcessException: Unable to evaluate new value for attribute 'FF_CONTENT': org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: ${FF_CONTENT:jsonPathAdd('$linkedData',${callid})} due to Unexpected token 'jsonPathAdd' at line 1, column 13.
Created 01-29-2020 12:01 AM
NiFi 2.11 ? I must have missed something...
Let's assume it is 1.11.0 then the used function should be available.
I think there is a typo in your Expression Language.
${FF_CONTENT:jsonPathAdd('$.linkedData', ${callid})}
There has to be a dot between $ and linkedData.
Created on 01-29-2020 12:25 AM - edited 01-29-2020 12:38 AM
Apologies I gave wrong version.nifi 1.9.2
Also I tried correcting syntax
Invalid Expression: ${FF_CONTENT:jsonPathAdd('$.linkedData',${callid})} due to Unexpected token 'jsonPathAdd'
Created 01-29-2020 12:53 AM
@janapati10
Oh, too bad, this options for manipulating JSON with Expression Language are - as far as I know - not available before 1.10.0.
When the JSON-format is really stabil maybe this will work for you.
UpdateAttribute ==> ${FF_CONTENT:substringBefore('['):append('["'):append(${callid}):append('"]'):append(${FF_CONTENT:substringAfter(']')})}
It is not "elegant" but I haven't got another idea, sorry.