I think this is a great question.
We like to think of all Device State data as being time-series data. Since time-series data is optimized for aggregations, that’s why they are single values (number, boolean, etc.). It’s tough to aggregate a complex JSON object over a specified amount of time.
But you do have options!
-
Because Device State can be a string, we’ve seen cases where other Losant Developers have encoded the JSON and stored that value as the attribute. But, this is not the best because you’ll always need to encode/decoded to use/store that value. Overall, we recommend saving the single values as this would allow you to aggregate and visualize them efficiently.
-
If the data is not time series, or you need data associated with a Losant Device or Experience Users, you can store it in a Data Table.
A note on the JSON Template, from this:
I know that there are two other input options to set a device state called “JSON Template” that seems to be taking only manual entry values and “Payload Path” that seems to be taking only linear (n-1 depth) payload JSON. It does not seem to be handy for storing JSON-complex states of devices and moreover extracting it for processing later on.
These, can allow you to set all of these in one place, and access nested values and arrays:
{
"attr1": "{{data.some.nested.value.[4].array.value}}",
"attr2": "{{data.value }}",
}
There are a ton of options here: