Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert(::Type{Dict{Symbol,Any}}, ::JSON.Object) fails #19

Open
SteffenPL opened this issue Feb 21, 2020 · 0 comments
Open

convert(::Type{Dict{Symbol,Any}}, ::JSON.Object) fails #19

SteffenPL opened this issue Feb 21, 2020 · 0 comments

Comments

@SteffenPL
Copy link

For dictionaries which use Symbols as keys, the convert function fails.
Here is a minimal example to reproduce the error message

Dict{Symbol,Int64}( LazyJSON.value("""{"a":10}""") )

Output:

ERROR: ArgumentError: "a" is not a valid key for type Symbol
Stacktrace:
 [1] setindex!(::Dict{Symbol,Int64}, ::LazyJSON.Number{String}, ::LazyJSON.String{String}) at ./dict.jl:374
 [2] Dict{Symbol,Int64}(::LazyJSON.Object{Nothing,String}) at ./dict.jl:103
 [3] top-level scope at none:0

I am no Julia expert. Should it remain like this or would it be possible to add Symbols as supported keys?

Anyway, my workaround is to define

import Base.setindex!
function setindex!(d::Dict{Symbol,T}, v::LT, k::LazyJSON.String{String}) where {T, LT}
    setindex!(d,v,Symbol(k))
end

such that every LazyJSON.String is first converted to a Symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant