Created 10-08-2018 09:02 PM
Hi
How extract fields from flow file in json format are in square brackets. I am using Evaluate json path processor but not getting results . Please help me on this regards
[{"projetname":"ABC", "projectid": "ABC-12", "startdate" :"Aug-2018"}]
I was used the evaluate json path processor : projectidvariable --> "projectid":\s(.*?),
Thanks for your time and consideration
Created on 10-08-2018 10:10 PM - edited 08-17-2019 09:21 PM
EvaluateJsonPath processor accepts only valid json path's(ex:$.<key>..) as you are specifying Regex if you want to extract the values using Regex then use ExtractText processor and add your regex path in that processor.
Configure EvaluateJsonPath processor as shown below and keep Destination as flowfile-attributes and add new properties
projectid
$.[0].projectid
projetname
$.[0].projetname
startdate
$.[0].startdate
Output:
As you see in the above screenshot attributes are added to the flowfile, This way we are assuming there are only one json message in array and extracting the first message values and storing as flowfile attributes.
Cleaner way to do this task as follows:
as you are having array of json messages and want's to extract the values of the json key's so split the array of json messages into individual messages by using SplitJson processor.
SplitJsonConfigs:
Then use EvaluateJsonPath processor:
Configure the processor as show above this will work if you are having more than one json message in an array also.
Created on 10-08-2018 10:10 PM - edited 08-17-2019 09:21 PM
EvaluateJsonPath processor accepts only valid json path's(ex:$.<key>..) as you are specifying Regex if you want to extract the values using Regex then use ExtractText processor and add your regex path in that processor.
Configure EvaluateJsonPath processor as shown below and keep Destination as flowfile-attributes and add new properties
projectid
$.[0].projectid
projetname
$.[0].projetname
startdate
$.[0].startdate
Output:
As you see in the above screenshot attributes are added to the flowfile, This way we are assuming there are only one json message in array and extracting the first message values and storing as flowfile attributes.
Cleaner way to do this task as follows:
as you are having array of json messages and want's to extract the values of the json key's so split the array of json messages into individual messages by using SplitJson processor.
SplitJsonConfigs:
Then use EvaluateJsonPath processor:
Configure the processor as show above this will work if you are having more than one json message in an array also.
Created 08-27-2019 02:06 AM
Hey can you please help me with extracting regex attribute from a json file. I am trying to take attribute from a json file, this attributes have regex values. For ex: json file is - { "key1" : "(.{2})(.{4})", "key2" : "$1,$2"}
From this json file I would need to take key1 and key2 in replacetext processor to search(key1) and replace by (key2). Please suggest a way to do this. Thanks!!
Created 10-09-2018 12:00 PM
Hi
@Shu thank you very much for your help and support . I willtry this solution