Help please - order json data

Hi I’m having issues order the json data into something more readable.
What I’m looking for is a top 10 of keys with the belonging impressions put together. The rest (clicks, crt and position can be ignored or filtered-out somehow)
any advice is appreciated.

the rest sensor has an output like:

rows:
  - keys:
      - mysite
    clicks: 0
    impressions: 1
    ctr: 0
    position: 80
  - keys:
      - my beautiful site
    clicks: 0
    impressions: 1
    ctr: 0
    position: 26

when I execute this in the template tester it gives me an error

{{ state_attr('sensor.google_api', 'rows') 
| sort(reverse=true, attribute='impressions') | map(attribute='keys','impressions') | list  }}

Output:
TemplateSyntaxError: invalid syntax for function call expression

When I execute this, it gives me only the “keys” but not the belonging impressions:

{{ state_attr('sensor.google_api', 'rows') 
| sort(reverse=true, attribute='impressions') | map(attribute='keys') | list  }}

output:

[
  [
    "mysite"
  ],
  [
    "my beautiful site"
  ],

What I’m looking for is an output like, so without the brackets:

"mysite"
"23",
"my beautiful site"
"54"
etc

You can’t map multiple attributes. If you want a list of information,

[{% for row in state_attr('sensor.google_api', 'rows') | sort(reverse=true, attribute='impressions') %}
  "{{ row.keys[0] }}", {{ row.impressions }},
{% endfor %}]

Hi Petro this gives me an output like

[
  "", 387,

  "", 159,

  "", 119,

but without the keys. Isn’t possible to put the keys name before the number?

Yes, that’s what I did based on your posted data.

if this isn’t correct, then my code wont’ be correct.

then I would expect a result like this:

[
  "mysite", 387,

  "my beautiful site", 159,

somehow the keys name isn’t included?

there should be an error in your logs if that’s the case.

You can try this, it’s possible that keys is a method.

[{% for row in state_attr('sensor.google_api', 'rows') | sort(reverse=true, attribute='impressions') %}
  "{{ row['keys'][0] }}", {{ row.impressions }},
{% endfor %}]

exactly what I was looking for, thanks!