I made a recursive function to extract a value from a JSON given the key for that

I made a recursive function to extract a value from a JSON given the key for that value:

function extract(json, key)
    req = []

    for (k, v) in pairs(json)
        if k == key
            println("FOUND $key == $k")
            println("value: $v")
            println("type: $(typeof(v))")
            push!(req, v)
        elseif typeof(v) <: AbstractDict
            extract(v, key)
        end
    end
    req
end

I tested this function with the following Dict: Dict(:a => Dict(:b => "wrong"), :Src => "GOLD")
With the expected result: It returns an Array{Any, 1} with the value "GOLD"

However, when I try it with the real use case in mind it doesn’t return anything. The real use case is that I get two JSON payloads from an HTTP request and read them using JSON3.read() . I then put those two JSONs in a dict. The resulting type of the Dict is: Dict{Symbol,JSON3.Object{Array{UInt8,1},Array{UInt64,1}}} .
The print statements run when it finds the key but for some reason it doesn’t push the value (v) to the req List and so it returns nothing. The same thing happens if I substitute the push!() with a return v instead. Nothing is returned.

Any ideas?

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

Some of the symbols got mangled when posting from Slack.
The function was tested with a small Dict that can be reproduced like so:
test_dict = Dict(:a => Dict(:Src => "GOLD"), :Channel => "x")
And the real case Dict looks something like this:

Dict(
    :app => {
        :TrafficSource => "x"
        :Label => {
            :Channel => "y"
            :Domain => ".com"
            :Src => "123"
        }
    }
)

I have come up with a working solution now:

function extract_json(json, key)
    req = []
    function extract(json, key)
        for (k, v) in pairs(json)
            if k == key
                push!(req, v)
            elseif typeof(v) <: AbstractDict
                extract(v, key)
            end
        end
    end
    extract(json, key)
    Set(req)
end

The weird thing is that a version were I don’t push to an Array an instead just return the value when the key is found doesn’t return the value even if the first conditional branch is entered. (Which I checked with some print statements). I’m looking for something like this:

function extract2(json, key)
    for (k, v) in pairs(json)
        if k == key
            return v
        elseif typeof(v) <: AbstractDict
            extract(v, k)
      end
    end
end