Is it possible to somehow insert list as a value in InfluxDB? This is the json:
json_body = [
{
"measurement":"devices",
"tags":{
"host":"server01",
"region":"us-west"
},
"fields": {
"device":1234,
"coord":[60.177751,24.913778],
"local":[[244,5,'232E','F27B',23],[244,5,'232F','76FE',9]]
}
}
]
Alternative would be to use string representation of list but then I have to convert it to list like below, which works fine.
ast.literal_eval(device_points[0]['local'])
Here is the json object with string representations:
json_body = [
{
"measurement":"devices",
"tags":{
"host":"server01",
"region":"us-west"
},
"fields": {
"device":1234,
"coord":"[60.177751,24.913778]",
"local":"[[244,5,'232E','F27B',23],[244,5,'232F','76FE',9]]"
}
}
]
client.write_points(json_body)
query = 'select local from devices;'
print("Querying data: " + query)
result = client.query(query)
device_points = list(result.get_points(measurement='devices'))
Is there some other way to achieve writing of lists directly?
Thanks!
You could probably store the list as a string, but then you would not have any way of manipulating it afterwards as influxdb is rather poor on string manipulation and lacks ways of extracting infos from strings and turn them into fields.
So yes, the above suggestion to split it into fields is probably your best option if you want to stick with influxdb.