Does LightDB State support arrays?

When using LightDB State, the following array:

{
“foo”: [10, 20, 30]
}

will automatically get turned into:

“foo”: {
“0”: 10,
“1”: 20,
“2”: 30
}

This isn’t a problem per se, but it suggests that LightDB may not support arrays - is this true?

Or are arrays supported in LightDB State, you just need to ensure you use the appropriate e.g. JSON_OBJ_DESCR_ARRAY to parse it correctly in firmware?

Cheers,
Mathew

1 Like

@mathew thank you for reporting this behavior! LightDB State can handle arrays, but what you are observing is a confusing behavior in how the console interacts with the LightDB State API. The console always replaces the entire LightDB State object with the provided values, which causes nested child arrays to be converted to the indexed map format.

We are looking into addressing this behavior as it is not intuitive. However, in the meantime you can work around this by calling the API directly with the specific path for the array and the array itself as the top-level value. See the following example:

curl 'https://api.golioth.io/v1/projects/{your_project}/devices/{your_device_id}/data/foo' \
  -X 'PUT' \
  -H 'X-API-Token: {your_api_token}' \
  -H 'content-type: application/json' \
  --data-raw '[10, 20, 30]'
1 Like

That worked! Thanks a lot.