FernOfTheAndes
FernOfTheAndes

Reputation: 5015

Unicode escape sequence in NIFI flow to convert JSON to XML

Using a sequence of GenerateTableFetch, ExecuteSQL, SplitAvro, and ConvertAvroToJSON processors, I am fetching a JSON field from a MySql view that has this content:
"A 7-point scale (1=\u201Cnot at all\u201D to 7=\u201Cextremely\u201D) is used.."

If I view the content of the file in a queue and chose option formatted (as opposed to original), I get this:
"A 7-point scale (1=“not at all” to 7=“extremely”) is used..."

And this unescaped string is what I would like to store in a NoSQL db. Is this in-built NIFI viewer using a function that I can tap into?

I am asking this because later in the flow, I wrap the JSON within an xml tag in order to transform it to XML using an XSLT stylesheet. But I end up with the unicode characters after the transformation and would like to retrieve back the original unescaped JSON (before I store it in the NoSQL db).

Upvotes: 0

Views: 1562

Answers (1)

Andy
Andy

Reputation: 14194

You can use a ReplaceText processor to replace all instances of a byte sequence (\u201C) in the flowfile content with . If you need the leading and trailing quotes to be different, you can use ReplaceTextWithMapping to associate the different Unicode code points with the specific replacement value. If you don't, you can just use the generic ReplaceText, match \u201[CD], and replace it with ".

Upvotes: 1

Related Questions