# How To Quickly Iterate over a Collection of Dictionaries?

**URL:** <https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588>\
**Category:** General Usage\
**Tags:** performance, dictionary\
**Created:** [February 5, 2025, 5:23pm UTC](https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588 "2025-02-05T17:23:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [February 5, 2025, 5:23pm UTC](https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588/1 "2025-02-05T17:23:40Z")

</div>

Hi folks! 👋

I have a rather large JSON file. The good news is that the JSON is not heavily nested (only 2 levels deep). What is the most efficient way to filter relevant parts of a JSON structure I need based on a condition? What I was imagining was something like this:

```julia
for item in json_data
    if item.condition == "Condition"
        push!(filtered_data, item)
    end
end

```

Is there a better way to do this? I read in the JSON data with JSON3.jl so really, I am just iterating over a ton of dictionaries. Any suggestions?

* * *

Another way to phrase this question:

I have a collection of dictionaries and I need to iterate over them quickly to pick out the dictionaries I want based on a key-value pair within each dictionary. What is the quickest way to iterate over all these dictionaries in Julia?

Yours,

~ tcp 🌳

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [February 5, 2025, 9:16pm UTC](https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588/2 "2025-02-05T21:16:50Z")

</div>

How does the JSON structure look like? If it’s something DuckDB can handle, it can be efficient to delegate reading and filtering to it:

```julia
using SQLCollections
using QuackIO
using Accessors

read_json(SQLCollection, "https://duckdb.org/data/json/todos.json") |>
	filter(@o _.completed && startswith(_.title, "a")) |>
	collect

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/3/d3c85cba6f092f114f8f21b071ea690558bb93a7.png)  
Here, everything before `collect` (loading and filtering) happens lazily in DuckDB. Only the final result is materialized.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 5, 2025, 9:35pm UTC](https://discourse.julialang.org/t/how-to-quickly-iterate-over-a-collection-of-dictionaries/125588/3 "2025-02-05T21:35:51Z")

</div>

It might help to parallelize

```julia
ixs = OhMyThreads.tmap(dicts) do d
  d.condition == "c"
end
dicts[ixs]

```
