when you have escape characters in the string the liquid template fails

I came across a scenario, where I got bad request error when I have double quotes(“) in my incoming string property while performing json to json transforming using liquid template. When there is not double quotes it works as expected. 

 My Liquid Template: performing a simple append of first name and last name

{    “fullName”: “{{content.FirstName | Append: ‘ ‘ | Append: content.LastName}}”,}

 When input message is:

{    “FirstName”: “Shashidharan”,     “LastName” : “Krishnan”  }

  

When input message contains doubles qoutes, which is still a valid json message.

“FirstName”: “\”Shashidharan”,”LastName” : “Krishnan” }

we get bad request error  

“body”: {        “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 ‘fullName’, line 2, position 19.'”,        “Details”: null,        “InnerError”: null      }

 

 This is basically a limitation with the underlying .liquid library. So we might need to use workaround to replace the escape character as below. 

Workaround:

{     “fullName”: “{{content.FirstName | Escape | Replace: ‘"’, ‘\”‘ | Append: ‘ ‘ | Append: content.LastName}}”  }