Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using flex table card with JSON #76

Open
galtamur opened this issue May 10, 2022 · 7 comments
Open

Using flex table card with JSON #76

galtamur opened this issue May 10, 2022 · 7 comments

Comments

@galtamur
Copy link

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.

@daringer
Copy link
Collaborator

daringer commented May 10, 2022

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)

@galtamur
Copy link
Author

galtamur commented May 10, 2022

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.

@daringer
Copy link
Collaborator

oh, then you could try:

modify: JSON.parse(x).my_data[0].field_a

@galtamur
Copy link
Author

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?

@daringer
Copy link
Collaborator

oh, nope this will not work to expand the json parsed with modify into multiple rows, sorry

@teskanoo
Copy link

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}]

@EdLeckert
Copy link
Contributor

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

MyData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants