Access in an array of hashes (worse: where the keys contains blanks)

Dear Jekyllers:

This topic does not seem to have been covered yet: So I’m reading in a data file (CSV, of scientific publications). When I look at the result with the debug filter, I see this:
“Item Type”=>“journalArticle”,
“Publication Year”=>“2020”,
“Author”=>“xx; Bach, Michael; xx.”,
“Title”=> …},
{“Key” … … …}, …
From this I conclude it’s an array (length ≈300) of hashes. I want to select from this like »all records (hashes) where the {publication year} is {SomeVariable}«. The where_exp filter does not work for me on an array of hashes. And to make matters worse, the keys contain space characters. [I would rather not rename the keys in the external file, but renaming the keys within Jekyll would be an option were I know how to rename a key in the entire array.]
What works for me, for example, is »myLib[0]["Publication Year"]« but I would need to iterate over all array elements and it becomes slow. Something like this »myLib[*]["Publication Year"]« (where * means entire array) would be great.

Looking forward to your advice, thanks, best, Michael

Answering half of my questions:
The where_exp automatically applies to the entire array. Great!
No solution so far for the problem when a hash key contains a space. So I fell back on renaming the keys in the data file outside of Jekyll.

Can you show what you tried?

If the problem is the space you can use hard brackets and quotes.

{{ myLib | where_exp: "item", "item["Publication Year" == 2010" }}

Based on

1 Like

Also your equals logic is simple enough to use the plain where filter.

{{ myLib | where: "Publication Year", 2010 }}

1 Like

Thank you for both pieces of advice! I had tried the brackets but did not know about the “item” nomenclature. And the simplification is even better! I will try this ASAP.
This is a very helpful community!

Thanks, best, Michael

Both solutions worked (needs 2 type of quotes, " & ', of course, in the first example). I ended up with the simplified version.
Great, thanks again! Michael

Great to hear its working for you.