In a workflow's JSON format, how can I use AppSheet's expression to include or exclude a JSON object? Currently, any value return by expression will be JSON stringify

Say, I want a part of JSON template to be included or excluded based on a condition and that part is a JSON object and not a simple string. Example:

<<IF(TRUE, '{"type": "text\ntext"}', '')>>

Currently, that would return a string with escaped text like
{\"type\": \"text\\ntext\"}

Note that above JSON is hand typing. So it might not have a valid format. It’s just to give you an idea.

And current workaround is create multiple workflows with different JSON template files but it is only good for templates with one or two condition checks.

One suggestion is to include a JSON type in AppSheet’s column type list. Anything printed from the JSON type will not be escaped (or stringify). :slight_smile:


Interesting challenge. You may want to consider putting your snippets into fields and/or columns in a data source, then, just refer to them by “name”, e.g.


(pattern1 and pattern2 are two different JSON snippets, [Name] is just a field I am keying off of)

Here’s a working example. Is this the kind of thing you were asking about? Or something else perhaps…

If you use [Pattern1] in a body template like in

Say [Pattern1] is { x: 5, y: 6 }
All those snippets will be stringify like this
JSON.stringify({ x: 5, y: 6 })
And it will be printed out like
"{"x":5,"y":6}" which is a string.

Unless I am completely misunderstanding your initial post, in your JSON body you can do things like:

{some JSON code}
<<If: (some condition in your table data)>>
{only sometimes JSON code}
<<If: (a different condition in your table data)>>
{only sometimes JSON code}
{more JSON code}

You don’t have to use the IF() from within AppSheet. You could even have multiple different JSON templates inside one file depending on a certain value from your data.

My personal example (JSON sent to Discord):


Thanks @Bahbus. That will work for my most use cases. But in some cases, I have a virtual columns with JSON snippets which is used by a cloud app via the AppSheet integration.

I also like to use the same snippets within the workflow template.

I could maintain the two set of JSON snippets but it could be an error-prone process.

I also created a feature request that will be from integration side. In cloud-service integrations, provide a way to response a POST request