Skip to main content
negiraj1989
Silver ⭐️⭐️
Apr 30, 2019 8:47 PM UTC
Solved

array response is having escape character

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



Shu_ashu
Shu_ashuAnswer
Gold ⭐️⭐️⭐️
May 1, 2019 7:06 AM UTC

@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






4 replies

Shu_ashu
Shu_ashuAnswer
Gold ⭐️⭐️⭐️
May 1, 2019 7:06 AM UTC

@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






Translate
negiraj1989
Silver ⭐️⭐️
May 2, 2019 3:33 AM UTC

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


Translate
Shu_ashu
Gold ⭐️⭐️⭐️
May 2, 2019 7:27 AM UTC

@Raj Negi

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


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

Translate