JSON Expression Bug: <<If: true>> something <<EndIf>> will automatically include a comma

<<If: true>> something <<EndIf>> will automatically include a comma. So it will produce

something,

That lead to some issues.

  1. The body of the if statement is a JSON object and it is at the end of JSON, that will lead to a trailing comma
  2. If we use the if statement within a normal tax in a JSON template, that will add unnecessary comma.

If I am missing on using the <If: >> statement, please let me know.

Thanks

0 4 492
4 REPLIES 4

Please read this thread

Hi @Phil
Related to https://community.appsheet.com/t/does-a-start-expression-output-a-comma-be/936/8

I understand that adding comma between members of a list will be tricky but โ€œifโ€ statement should not be a problem.

In terms of syntax , can you add new expressions?
E.g <<start1>> or <<if1>> and within those new expression, no comma will be added. That will be similar to how frameworks introduce new functions without breaking old ones.

Thanks @Marc_Dillon for the link.

Hi @Steven_Aung just wondering if you found a solution or workaround to this problem in a JSON template?

I've encountered this issue with a Webhook POSTING JSON to a external API. I want to control the value of a specific JSON property based on the value of an Appsheet field, like so:

// rest of JSON template omitted for brevity

"name": "<<If:([Account_Group]='DTC')>>welcome_message_dtc<<EndIf>><<If:([Account_Group]='Partner')>>welcome_message<<EndIf>>",

The If statements add an extraneous ',' at the end, which is not what the external API is expecting so the call fails. 

Did you find a workaround?

Just FYI for anyone finding this thread, I raised the issue with Appsheet support, who gave the solution of replacing <<If>><<EndIf>> with an Appsheet If() expression. This worked in my case of a webhook posting a JSON Payload to an external API, so just sharing here in case it helps others.

Top Labels in this Space