0
votes

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 ?

2
FYI there is a function for escaping json in expression language nifi.apache.org/docs/nifi-docs/html/… - Sdairs

2 Answers

0
votes

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()}

0
votes

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.