Support Questions

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

NIFI Replace Text issue

avatar
Explorer

I have input NIFI flow content:

{"page_id":"page_bb51c576-a885-482f-bf19-648f0b654745","group_id":"MFGRPPA000054","provider":"{\"addresses\":\"[\\\"1405 Shady Avenue, Pittsburgh, PA\\\"]\",\"education\":\"[{\\\"name\\\":\\\"TEXAS A&M UNIVERSITY COLLEGE OF MEDICINE\\\",\\\"graduation_date\\\":\\\"\\\"}]\",\"last_name\":\"Oandasan\",\"affiliations\":\"\",\"middle_name\":\"\",\"suffix\":\"\",\"certifications\":\"[\\\"ADULT PSYCHIATRY, CHILD & ADOLESCENT PSYCHIATRY – AMERICAN BOARD OF PSYCHIATRY AND NEUROLOGY\\\"]\",\"degrees\":\"[\\\"MD\\\"]\",\"internships\":\"[]\",\"fellowships\":\"[]\",\"phone_numbers\":\"[\\\"4124202400\\\",\\\"41242024001405\\\",\\\"8007320999\\\"]\",\"specialties\":\"[\\\"CHILD & ADOLESCENT PSYCHIATRY\\\"]\",\"residencies\":\"[\\\"GENERAL PSYCHIATRY, GEORGETOWN UNIVERSITY\\\"]\",\"name\":\"Aileen Oandasan\",\"state\":\"PA\",\"first_name\":\"Aileen\"}","org_name":"CHILDREN'S INSTITUTE OF PITTSBURGH, THE","scrape_id":"scrape_42d77b5d-19c1-4760-94bc-1fdf4c3b1d79"}

I need to replace the content with following

]\" => ]

\"[ => [

\ => empty

Can you please help me how to achieve this in NIFI?

Thanks,

Bob

2 REPLIES 2

avatar
Master Guru
@Bob T

You can achieve that by using three successive replace text processors with the below

Configs:-

Replacetext1:-

Search Value

\]\"

Replacement Value

]

Maximum Buffer Size

1 MB

Replacement Strategy

Regex Replace

Evaluation Mode

Entire Text

62878-replacetext1.png

Replacetext2:-

Search Value

\"\[

Replacement Value

[

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

62879-replacetext2.png

ReplaceText3:-

in this processor we are trying to replace \(backslash) with empty string.

Search Value

\

Replacement Value

Empty string set 

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

62880-replacetext3.png

The output from the last replacetext processor would be

{
"page_id": "page_bb51c576-a885-482f-bf19-648f0b654745",
"group_id": "MFGRPPA000054",
"provider": "{"addresses":["1405 Shady Avenue, Pittsburgh, PA"],"education":[{"name":"TEXAS A&M UNIVERSITY COLLEGE OF MEDICINE","graduation_date":""}],"last_name":"Oandasan","affiliations":"","middle_name":"","suffix":"","certifications":["ADULT PSYCHIATRY, CHILD & ADOLESCENT PSYCHIATRY – AMERICAN BOARD OF PSYCHIATRY AND NEUROLOGY"],"degrees":["MD"],"internships":[],"fellowships":[],"phone_numbers":["4124202400","41242024001405","8007320999"],"specialties":["CHILD & ADOLESCENT PSYCHIATRY"],"residencies":["GENERAL PSYCHIATRY, GEORGETOWN UNIVERSITY"],"name":"Aileen Oandasan","state":"PA","first_name":"Aileen"}",
"org_name": "CHILDREN'S INSTITUTE OF PITTSBURGH, THE",
"scrape_id": "scrape_42d77b5d-19c1-4760-94bc-1fdf4c3b1d79"
}

Flow:-

62881-flow.png

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

avatar

I guess you need to drop these expressions one at a time. Using multiple ReplaceText processors. For example for the first pattern, you can use the replace text as follows.

Similarly, you can replace your patterns in the "Search Value" text box with following expressions.

(?s)(\\\"\[)

(?s)(\\)

Hope that helps!