简体   繁体   中英

apache Nifi : updateAttribute processor

I'm trying to update an attribute (for example let's call it myAttribute) in order to replace all " by \" for example:

  • {"field1":1,"field2":{"field21":21,"field22":"22"}} will become
  • {\"field1\":1,\"field2\":{\"field21\":21,\"field22\":\"22\"}}

for that purpose I'm using the updateAttribute procesor with the replaceAll function for example:

  • property: myAttribute
  • Value: ${log.message:replaceAll('"','\"')}

the result is the same (\ is used as escape sequence prefix) I tried to use also two \\ but the result is the same.

Someone can help me?

Well, it seems like there's a bug in the replaceAll function of the expression language..

But anyways, it seems like you're trying to escape your Json which escapeJson would solve..

So instead, just use ${log.message:escapeJson()}

Probably escapeJson is the best option but if you need to do it with replaceAll , try this:

  • ${log.message:replaceAll("\"","\\\\\"")}

or

  • ${log.message:replaceAll('"','\\\\"')}

I've tested with NiFi 1.9.0 and it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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