Automation variables could be objects/arrays

The new variables feature in automations is great, and I’ve already started using it to simplify some of my automations. One thing I noticed is that the variables are all strings, even if I try to set an array or object. I assume this is a natural output of Jinja2 templates, but I’m wondering if maybe the variables parser could detect the JSON and deserialize it automatically. That would make variables much more useful.

For example, an object variable could be used to simplify accessing properties of nested trigger objects:

variables:
  data: "{{trigger.event.data}}"
  #this next line fails because data is a JSON string rather than the desired object
  value: "{{data.value if data.value is string else data.value|random if data.value}}" 

Another example is if I want to capture an array into a variable:

variables:
  message: "{{trigger.event.data.message}}"
  #message is always a string even if trigger.event.data.message was an array
  value: "{{message if message is string else message|random if message}}"

Casting numbers as the right numeric data type would be handy too, but that’s not too hard to work around in the meantime.

Maybe not for long.

Awesome! That’s exactly what I was asking for. I sure hope that gets merged!