Expensify.org is accepting proposals for new campaigns. Submit yours here by April 30th to receive up to $100,000 in funding for campaigns dismantling injustice related to: Climate, Homes, Hunger, Reentry, or Youth.
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
-
Francois Laithier Expensify Team Posts: 27 Expensify Team
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?
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeHi @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?
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeHi @Sasha Kluger , I got the follwoing response:
{"responseMessage":"Could not process template","responseCode":500}
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomePlaying with it, I found out that if change to
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.
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeInteresting - 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.
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeHi @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?
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up AwesomeGreat! Thanks @Francois Laithier that made the job!!!!
- Spam
- Abuse
- Report
0 · Accept Answer Off Topic Insightful Vote Up Awesome