flex-table-card
flex-table-card copied to clipboard
Using flex table card with JSON
Hello, I am trying to use the Flex Table Card with a sensor providing a JSON coming from a query. The JSON is as follows: {"my_data":[{"field_a":"a","field_b":"b"},{"field_a":"a","field_b":"b"}]} If I configure the card this way: columns:
- name: hhh data: prova modify: x I see the string of the json as result.
If I configure the card this way: columns:
- name: hhh data: prova modify: x.field_a I see undefinedundefinedundefined as result.
Where is my error? Or there is an issue somewhere? Thank you for helping.
mmmh, if the json data is as you say then I would maybe try:
modify: x.my_data[0].field_a
maybe with quotes:
modify: 'x.my_data[0].field_a'
because you have a map (field_a
) inside a list ([0]
) inside a map (my_data
)
It's showing nothing... Neither with nor without quotes, neither with or wthout [0]. By the way, it's showing nothing, not undefinedundefinedundefined. I also tried x[0] and it shows the first character of the string, i.e. "{". Looks like he sees the string as... a string, and not as a json object.
oh, then you could try:
modify: JSON.parse(x).my_data[0].field_a
I tried this, and it's better, but it shows the first record. In other words, out of: {"my_data":[{"field_a":"a1","field_b":"b"},{"field_a":"a2","field_b":"b"}]} it shows a1, whereas I expect to see a table with a column with to rows, with a1 and a2 respectively... Ideas?
oh, nope this will not work to expand the json parsed with modify
into multiple rows, sorry
Hi Markus
I too am really struggling with this - it would really be nice to just be able to feed json data into this (totally awesome) card
is this something that could be supported (or already is and I am misunderstanding how to implement it)?
- type: 'custom:flex-table-card'
title: Load from Json
strict: false
columns:
- data: AA
- data: BB
- data: CC
entities:
include: [{"AA":9.3,"BB":380,"CC":1300},{"AA":1.3,"BB":180,"CC":1100}]
Or this
- type: 'custom:flex-table-card'
title: Load from Json
...
entities: [{"AA":9.3,"BB":380,"CC":1300},{"AA":1.3,"BB":180,"CC":1100}]
Or this
- type: 'custom:flex-table-card'
title: Load from Json
...
json: [{"AA":9.3,"BB":380,"CC":1300},{"AA":1.3,"BB":180,"CC":1100}]
To display the JSON in the original comment, from an entity input_text.mydata
with an attribute prova
, you could use:
type: custom:flex-table-card
title: My Data
entities:
include: input_text.mydata
columns:
- name: Field A
data: prova.my_data
modify: x.field_a
- name: Field B
data: prova.my_data
modify: x.field_b