I have a wso2 stream processor code where i am receiving input from kafka as text format because debezium mongodb connector gives out a lengthy output and it's not a valid json to send to WSO2. So, i am receiving it as text and plans to use regex to get only the part of payload i need. I am not able to figure out how to convert this text format to json so that i can send it to another kafka stream and do custom json mapping on this.
Another approach i am trying: I am also trying custom mapping for text:
@source(type='kafka',
topic.list='demo',
partition.no.list='0',
threading.option='single.thread',
group.id="group",
bootstrap.servers='localhost:9092',
@map(type='text',fail.on.missing.attribute='false', regex.A='(.*)',
@attributes(id = 'A[0]')))
define stream transactionstream1(id string);
Sample Json:
{"_id":{"$oid":"342fs"},"code":"ffssefse","name":"test1","desc":"description1","transRefId":"esfef3423des","amount":1000,"currency":"INR","requestId":null,"redeemedCashcode":null,"sender":{"id":"5d9c0dedcf71a09664922042","name":"tat","phone":"3242324"}}
Regex to get code attribute from above json is : (?:"code":")(.*?)(?:")
but wso2 regex.A is not accepting this.
Thats why currently i am getting entire data in text format and trying to convert to json
Is there some other approach to this? or some other convention of writing regex in wso2 stream processor?
I need to get individual attributes in custom mapping from text from the above json in wso2sp.
Since your regex consist of ", you need to escape that using 3 double quotes as follows,
regex.A = """(?:"code":")(.*?)(?:")""",