Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Please see the Cloudera blog for information on the Cloudera Response to CVE-2021-4428

Extracttext from Json with multiple fields and ignore the other ones

Explorer

I have json object that includes the below:
 {
"x":"avc123.abc.com",
"z":"24 - ny"
}
and I would like to only target "x" value for "123" (numbers only) and the rest won't get picked up such as "z"
so the expected output would be {
"x":"avc123.abc.com",
"z":"24 - ny",
"y":"123"
}

please note that the "z" value of "24" is not being picked up. "y" value is only being picked up from  x value. 

I already done the below 

Add new property in ExtractText processor 

val

 

 

(\d+)

 

 

 -

Then use ReplaceText processor with below configs:

Search Value

}
Replacement Value
,"y":"${val}"}
Character Set
UTF-8
Maximum Buffer Size
1 MB
Replacement Strategy
Literal Replace
Evaluation Mode
Entire text

-

1 REPLY 1

Super Guru

@ANMAR 

Try with this regex in ExtractText processor.

(?:"x":.\w+?)(\d+)

This regex will extract only the digit in "x" key and adds that value for "y" key in ReplaceText processor.