Created 11-22-2018 10:53 AM
Hello,
I have below json as flowfile content -
{
"organization_id": "life-360",
"message_type_id": "MSG01",
"consent_required": "1",
"country_list": [ "GB", "IT", "BG" ]
}
I want below content as output -
GB, IT, BG
I am able to get
"country_list": [ "GB", "IT", "BG" ] in flow file using JOLT but not comma separated country list.
Could any one please help with best way?
Thanks,
Mahendra
Created on 11-23-2018 12:25 AM - edited 08-17-2019 04:29 PM
AFAIK we cannot extract only the value using Jolt transform.
To achieve this extract the array from the json using `EvaluateJsonPath` processor
EvaluateJsonPath Configs:
Now using ReplaceText processor replace ",[,],space from the extracted value using NiFi expression language.
ReplaceText Configs:
Search Value
(?s)(^.*$)
Replacement Value
${country_list:replaceAll('(\[|\]|"|\s)','')}
Character Set
UTF-8
Maximum Buffer Size
1 MB
Replacement Strategy
Always Replace
Evaluation Mode
Entire text
Input:
{ "organization_id": "life-360", "message_type_id": "MSG01", "consent_required": "1", "country_list": [ "GB", "IT", "BG" ] }
Output:
GB,IT,BG
Flow:
1.other processors 2.EvaluateJsonPath //extract the json array as attribute value 3.ReplaceText //replace the content of flowfile with extracted value 4..other processors
Created on 11-23-2018 12:25 AM - edited 08-17-2019 04:29 PM
AFAIK we cannot extract only the value using Jolt transform.
To achieve this extract the array from the json using `EvaluateJsonPath` processor
EvaluateJsonPath Configs:
Now using ReplaceText processor replace ",[,],space from the extracted value using NiFi expression language.
ReplaceText Configs:
Search Value
(?s)(^.*$)
Replacement Value
${country_list:replaceAll('(\[|\]|"|\s)','')}
Character Set
UTF-8
Maximum Buffer Size
1 MB
Replacement Strategy
Always Replace
Evaluation Mode
Entire text
Input:
{ "organization_id": "life-360", "message_type_id": "MSG01", "consent_required": "1", "country_list": [ "GB", "IT", "BG" ] }
Output:
GB,IT,BG
Flow:
1.other processors 2.EvaluateJsonPath //extract the json array as attribute value 3.ReplaceText //replace the content of flowfile with extracted value 4..other processors
Created 11-23-2018 05:54 AM
Thanks @Shu !
It worked, I was using 'Return type' as auto instead of json in EvaluateJsonPath.
Thanks for the reply 🙂