Velocity Template Language Parsing issue for Single Array Value in Workflows

:red_question_mark: What issue are we facing?

When using the .JSON() function on the response of an HTTP Request Action that returns an array, the behavior is inconsistent:

  • If the array has multiple items, it correctly returns a list (array).
  • But if the array has only one item, .JSON() treats it as a Map (i.e., a single object), not as an array.

:white_check_mark: What should be the correct behavior?

Regardless of how many items are in the array (one or many), the .JSON() function should always return an array to maintain consistent behavior.


:pushpin: Related Product Feature

This issue affects Workflows → Send Email (VTL) functionality.


This is quite funny and topical as I’ve struggled with the exact same issue today!

My work around for this is to create a branching workflow. The branch checks to see if the ‘array’ is greater then length 1. If so, treat it as such and therefore do a ‘send email’ action without any foreach loop. If not, you can use the foreach logic in your template.

The compare step I’m using.

            "Compare Numbers": {
                "actionId": "sp:compare-numbers",
                "choiceList": [
                    {
                        "comparator": "NumericGreaterThan",
                        "nextStep": "Send Email 2",
                        "variableA.$": "$.getListOfIdentities.identities.length()",
                        "variableB": 1
                    }
                ],
                "defaultStep": "Send Email",
                "description": null,
                "displayName": "",
                "type": "choice"
            },

Hi @sauvee,

Thank you for your reply .
Yes, I did implement it this way.

It wasn’t easy to figure out what was going wrong :face_with_head_bandage: