Support Questions

Find answers, ask questions, and share your expertise

Nifi EvaluateJsonPath remove escape

avatar
New Contributor

Hi,

First of all, a data sample :

{
  "type" : "Feature",
  "properties" : {
    "commune" : "VENISSIEUX",
    "voie" : "Rue Eugène Hénaff",
    "numerodansvoie" : "10",
    "gestionnaire" : "NET Sud-Est",
    "observation" : "Entrée Subdivision NET SUD-EST face \"magasin\"",
    "identifiant" : "C61544",
    "gid" : "15"
  }
}

We can see about the observation field value, there are double quotes already escaped from the source. Perfect for the next operations, but...

When I use EvaluateJsonPath to set an flowfile attribute from this value, like this :

observation ----> $.properties.observation

Value is not :

Entrée Subdivision NET SUD-EST face \"magasin\"

But :

Entrée Subdivision NET SUD-EST face "magasin"

Double quotes are removed. This is a problem because I push this data in MariaDB. So classic "syntax error".

There are lot of solutions like ReplaceText, "?" with sql.args (but sometimes values are empty, an exception occurs). But there is a solution with EvaluateJsonPath directly ?

Thanks !

1 REPLY 1

avatar
Master Guru

I'm not sure if there is a function in JSONPath to retain the escaped quotes or not, but you could use UpdateAttribute (between EvaluateJsonPath and ReplaceText) along with the escapeJson function to "re-introduce" the quotes, by setting the "observation" attribute to the following value:

${observation:escapeJson()}