Skip to content

Is it possible to iterate over key/value values like a map or dictionary? #898

Closed Answered by tylerjl
tylerjl asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the input, @w-lfchen! That's helpful context.

For future users, this is very possible via some of the jq filters that are available. Although there isn't necessarily a way to make (for ... accept a key/value dictionary directly, you can just reformat json structures in a variety of ways that you can then loop through. For example, acquire the keys to EWW_BATTERY:

(for battery in {jq(EWW_BATTERY, 'del(.total_avg) | keys')}
  (power :battery battery))

...and then index into it:

(defwidget power [battery]
  (label :text "${EWW_BATTERY[battery].capacity}%"))

Other jq filters like to_entries can help as well.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tylerjl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants