vanpersil
vanpersil

Reputation: 814

Escaping xml encoded quotes in azure liquid mapping

I've been struggling for some time with the following problem. I have an xml which has to be transformed to json using liquid mapping on azure. Sometimes a node contains xml encoded double quotes, like this:

<node>
    <value>&quot;some string&quot;and the rest</value>
</node>

my liquid mapping looks like this:

"name":"{{ node.value }}"

The result of the mapping is a following error:

{
  "Code": "IncorrectLiquidTransformOutputType",
  "Message": "An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: s. Path '[205].node[9].value', line 32305, position 13.'",
  "Details": [
    {
      "Code": "IncorrectLiquidTransformOutputType",
      "Message": "{\"ClassName\":\"Microsoft.Azure.Function.Common.ErrorResponses.ErrorMessageException\",\"Message\":\"An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: s. Path '[205].node[9].name', line ....., position 13.'\",\"Data\":null,\"InnerException\":{\"ClassName\":\"Newtonsoft.Json.JsonReaderException\",\"Message\":\"After parsing a value an unexpected character was encountered: s. Path '[205].node[9].value'....",
      "Details": null,
      "InnerError": null
    }
  ],
  "InnerError": null
}

This means that the character " is properly decoded to double quote, and then it causes problems with the json. I need to keep this character like this:

"name":"\"some string\"and the rest"

any ideas how to do it?

Upvotes: 0

Views: 1338

Answers (2)

Johan Burman
Johan Burman

Reputation: 31

I got the exact same issue, but I convert the xml to json before passing it through the liquid transform. So the transformation gets a properly escaped json string:

"name":"William \"Billy\" Bob" 

I tested the proposed solution above (which looks a bit weird since it replaces any occurrence with the same value), and at first it didn't do anything. However, after some fiddling around, I removed the first Replace and then it actually worked.

{{ node.value | Replace: '\"', '\"'}}

Upvotes: 1

Frolos
Frolos

Reputation: 1

did you try to escape them in the output?

"name":"{{ node.value | Replace: '\' , '\' | Replace: '\"', '\"'}}"

Upvotes: 0

Related Questions