API could not process template

I have a json template that works quite well. I have some issues when string type data contain quotes, it leads to not valid json. So I use the function ?json_string like this to escape quotes:
"comment": "${expense.comment?json_string}",
but for unknown reasons template does not work anymore. Any ideas? Ty
Best Answer
-
Hi @gg1234,
Can you please confirm if your template contains the line:
<#if expense.units?hasContent >
If that's the case, this line needs to be replaced with
<#if expense.units?has_content>
The line with
"${expense.comment?json_string}"
is correct and shouldn't cause any issues.Cheers
Answers
-
It could be that version of FreeMarker used does not support that function?
-
Hi @gg1234 could you please provide more context around what you mean when you say it doesn't work? Did you get an error response back, or did the function just not return data, or something else?
-
Hi @Sasha Kluger , I got the follwoing response:
{"responseMessage":"Could not process template","responseCode":500}
-
Playing with it, I found out that if change to
"comment": "${expense.comment?lenght}",
It works. So to me it looks like API is not able to manage the template when I use that function. I need to escape quotes since they lead to a not valid json.
-
Interesting - I'm not personally familiar with the
?json_string
function, so I would need to do further testing to know for sure if it works with the Expensify API, but it sounds like you found a good alternative.FYI, I noticed a typo in your last code snippet (you mispelled "length" as "lenght). Not sure if this typo was in your template as well, but figured I should mention it just in case.
-
Hi @Sasha that is not a solution, was just an example to show that some functions work and some others not.
See here for details about json_string
As mentioned above I need to escape quotes in strings, do you know an alternative way?
-
Great! Thanks @Francois Laithier that made the job!!!!