Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

array response is having escape character

avatar
Explorer

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.

@Matt Burgess



1 ACCEPTED SOLUTION

avatar
Master Guru

@Raj Negi

After FetchHbaseRow processor use ReplaceText processor with below configs:

108329-screen-shot-2019-04-30-at-70220-pm.png

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






View solution in original post

4 REPLIES 4

avatar
Master Guru

@Raj Negi

After FetchHbaseRow processor use ReplaceText processor with below configs:

108329-screen-shot-2019-04-30-at-70220-pm.png

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






avatar
Explorer

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([]).


avatar
Master Guru

@Raj Negi

Use nifi expression language to replace function to replace "[ and ]" with [ and ]


${'$1':unescapeJson():replace('"[','['):replace(']"',']')} 

avatar
Explorer

Thanks @Shu

I had done the same in my case with some minor modifications.