Parse json to vector{T} for known T

Am trying to use the JSON package to parse “[1,2,3]” to a vector{Int64}.

I notice that the parse method has optional arguments dicttype and inttype. But it seems that whatever I give as as dicttype and inttype the function returns vector{any} instead of vector{Int64}. How should I specify these?

julia> using JSON
julia> x = JSON.parse("[1,2,3]"; dicttype=Vector{Int64}, inttype=Int64)
3-element Vector{Any}:
 1
 2
 3

JSON.jl doesn’t support this level of type specificity. You can use JSON3.jl which supports the syntax like JSON3.read(json, Vector{Int}).

1 Like