Skip to content

get error when key not found #412

@Beforerr

Description

@Beforerr

I felt like return the default should be better than error like Dict does.

MWE

julia> json=meta(da.BGSEc)
JSON.Object{String, Any} with 6 entries:
  "size"        => Any[3]
  "name"        => "BGSEc"
  "description" => "Magnetic Field Vector in GSE Cartesian coordinates (16 sec)"
  "units"       => "nT"
  "type"        => "double"
  "fill"        => "-1.0E31"

julia> get(json, :name,"")
ERROR: MethodError: no method matching find_node_by_key(::JSON.Object{String, Any}, ::Symbol)
The function `find_node_by_key` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  find_node_by_key(::JSON.Object{K, V}, ::K) where {K, V}
   @ JSON ~/.julia/packages/JSON/0oqO1/src/object.jl:124

Stacktrace:
 [1] get(f::JSON.var"#12#13"{String}, obj::JSON.Object{String, Any}, key::Symbol)
   @ JSON ~/.julia/packages/JSON/0oqO1/src/object.jl:135
 [2] get(obj::JSON.Object{String, Any}, key::Symbol, default::String)
   @ JSON ~/.julia/packages/JSON/0oqO1/src/object.jl:141
 [3] top-level scope
   @ REPL[108]:1
julia> dict=Dict{String,String}()
Dict{String, String}()

julia> get(dict, :name,"")
""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions