简体   繁体   English

NIFI 流中的 Unicode 转义序列将 JSON 转换为 XML

[英]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:使用一系列GenerateTableFetchExecuteSQLSplitAvroConvertAvroToJSON处理器,我从具有以下内容的 MySql 视图中获取 JSON 字段:
"A 7-point scale (1=\“not at all\” to 7=\“extremely\”) is used.." “使用了 7 分制(1=\“ 根本不\” 到 7=\“extremely\”)......”

If I view the content of the file in a queue and chose option formatted (as opposed to original ), I get this:如果我查看队列中文件的内容并选择选项formatted (而不是original ),我会得到:
"A 7-point scale (1=“not at all” to 7=“extremely”) is used..." “使用了 7 分制(1=“完全没有”到 7=“非常”)……”

And this unescaped string is what I would like to store in a NoSQL db.这个未转义的字符串是我想存储在 NoSQL 数据库中的。 Is this in-built NIFI viewer using a function that I can tap into?这个内置的 NIFI 查看器是否使用了我可以利用的功能?

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.我之所以这么问是因为在流程的后面,我将 JSON 包装在 xml 标记中,以便使用 XSLT 样式表将其转换为 XML。 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).但是我在转换后得到了 unicode 字符,并希望检索回原始的未转义 JSON(在我将它存储在 NoSQL 数据库之前)。

You can use a ReplaceText processor to replace all instances of a byte sequence ( \“ ) in the flowfile content with .您可以使用ReplaceText处理器将流文件内容中的字节序列 ( \“ ) 的所有实例替换为 . 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.如果需要前后引号不同,可以使用ReplaceTextWithMapping将不同的 Unicode 代码点与特定的替换值相关联。 If you don't, you can just use the generic ReplaceText , match \\u201[CD] , and replace it with " .如果不这样做,您可以只使用通用ReplaceText ,匹配\\u201[CD] ,然后将其替换为"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM