Created on 04-30-2019 01:47 PM - edited 09-16-2022 07:21 AM
I fetched the data from hbase using fetchHbaseRow and the response is in json format. but the value for the attribute is array of objects and it is having escaped characters in there.
A sample response is posted below:
{"someValues":"[{\"a\":\"6f7f8ffe-4837-4fc1-a5b9-45bc35727b69\",\"b\":\"da_states\",\"doc\":\"unknown\",\"idNew\":\"2846e8e1-5b17-490c-a99e-df1f1e3fa009\",\"status\":\"Approved\",\"scope\":\"Global\",\"dateModified\":\"2019-04-19T11:26:02Z\"}]"}
I need to split the objects in array and because of escape characters I am not able to.
Created on 05-01-2019 12:06 AM - edited 08-17-2019 03:42 PM
After FetchHbaseRow processor use ReplaceText processor with below configs:
Search Value
(?s)(^.*$)
Replacement Value
${'$1':unescapeJson()}
//capture all the data and apply nifi expression language unescapeJson function.
Character Set
UTF-8
Maximum Buffer Size
1 MB //change as per your flowfile size
Replacement Strategy
Regex Replace
Evaluation Mode
Entire text
Flow:
1.FetchHbaseRow 2.ReplaceText --other processors
Created on 05-01-2019 12:06 AM - edited 08-17-2019 03:42 PM
After FetchHbaseRow processor use ReplaceText processor with below configs:
Search Value
(?s)(^.*$)
Replacement Value
${'$1':unescapeJson()}
//capture all the data and apply nifi expression language unescapeJson function.
Character Set
UTF-8
Maximum Buffer Size
1 MB //change as per your flowfile size
Replacement Strategy
Regex Replace
Evaluation Mode
Entire text
Flow:
1.FetchHbaseRow 2.ReplaceText --other processors
Created 05-01-2019 08:33 PM
Thanks @Shu.
But this does not solve my problem. It does remove the \ from the json but the response is still not in the json response.
{"someValue":"[{"id":"6f7f8ffe-4837-4fc1-a5b9-45bc35727b69","name":"da_st","doc":"unknown","pnId":"2846e8e1-5b17-490c-a99e-df1f1e3fa009","status":"Approved","scope":"Global","dateModified":"2019-04-19T11:26:02Z"},{"id":"3559741f-76f6-4fb4-b919-6def5e0511fe","name":"Het","doc":"unknown","pnId":"2846e8e1-5b17-490c-a99e-df1f1e3fa009","status":"Approved","scope":"Global","dateModified":"2019-04-19T11:26:00Z"},{"id":"3b66fbda-9a16-48ac-9fd0-122e3826ef80","name":"queue","doc":"unknown","pnId":"2846e8e1-5b17-490c-a99e-df1f1e3fa009","status":"Approved","scope":"Global","dateModified":"2019-04-19T11:26:01Z"}]"}
The response should have been :
{"someValue":[{"id":"6f7f8ffe-4837-4fc1-a5b9-45bc35727b69","name":"da_st","doc":"unknown","pnId":"2846e8e1-5b17-490c-a99e-df1f1e3fa009","status":"Approved","scope":"Global","dateModified":"2019-04-19T11:26:02Z"},{"id":"3559741f-76f6-4fb4-b919-6def5e0511fe","name":"Het","doc":"unknown","pnId":"2846e8e1-5b17-490c-a99e-df1f1e3fa009","status":"Approved","scope":"Global","dateModified":"2019-04-19T11:26:00Z"},{"id":"3b66fbda-9a16-48ac-9fd0-122e3826ef80","name":"queue","doc":"unknown","pnId":"2846e8e1-5b17-490c-a99e-df1f1e3fa009","status":"Approved","scope":"Global","dateModified":"2019-04-19T11:26:01Z"}]}
The quotes should not be present before and after the array brackets([]).
Created 05-02-2019 12:27 AM
Use nifi expression language to replace function to replace "[ and ]" with [ and ]
${'$1':unescapeJson():replace('"[','['):replace(']"',']')}
Created 05-02-2019 04:57 PM
Thanks @Shu
I had done the same in my case with some minor modifications.