Probe if a variable exists in a JLD2-file

Is there a way to probe / evaluate if a variable exists in a JLD2-file?

ok one way is to load the whole content in a single dict and use haskey:

haskey(load("filename.jld2"), "varable_name_to_probe")

But for larger jld2-files that might not be the best option.
Are there other ideas?

Hi @ellocco,

this should do what you want, no?
There’s the github page and the linked docs with more info: GitHub - JuliaIO/JLD2.jl: HDF5-compatible file format in pure Julia

julia> using JLD2
[ Info: Precompiling JLD2 [033835bb-8acc-5ee8-8aae-3f567f8a3819]

julia> save("test.jld2"^C

julia> f = jldopen("test.jld2", "w")
JLDFile /home/isensee/test.jld2 (read/write)
  (no datasets)

julia> f["a"] = 42
42

julia> close(f)

julia> f = jldopen("test.jld2")
JLDFile /home/isensee/test.jld2 (read-only)
 └─🔢 a

julia> keys(f)
1-element Vector{String}:
 "a"

julia> haskey(f, "a")
true


julia> f["a"]
42

julia> close(f)

@JonasIsensee Hi,
I read the documentation and searched in the net.
But I was not creative enough to use haskey. Thanks for your support!