I am having difficulty using JSON3 and a dictionary with Tuple keys.
The first example works as expected the second does not. I have tried to use StructTypes to fix this, but I am missing something.
dString=Dict("p1"=>1,"p2"=>1,"p3"=>2,"p4"=>3)
@show buffS=JSON3.write(dString)
rString=JSON3.read(buffS,Dict{String, Int64})
produces
buffS = JSON3.write(dString) = "{\"p4\":3,\"p3\":2,\"p2\":1,\"p1\":1}"
Dict{String, Int64} with 4 entries:
"p4" => 3
"p3" => 2
"p2" => 1
"p1" => 1
but
DT=Dict{Tuple{Vararg{String}}, Int64}
@show dTuple=DT(("p1","c2")=>1,("p2","c2")=>1,("p3","c7","b100")=>2)
@show buffT=JSON3.write(dTuple)
rTuple=JSON3.read(buffS,DT)
produces
dTuple = DT(("p1", "c2") => 1, ("p2", "c2") => 1, ("p3", "c7", "b100") => 2) = Dict{Tuple{Vararg{String, N} where N}, Int64}(("p2", "c2") => 1, ("p1", "c2") => 1, ("p3", "c7", "b100") => 2)
buffT = JSON3.write(dTuple) = "{\"(\\\"p2\\\", \\\"c2\\\")\":1,\"(\\\"p1\\\", \\\"c2\\\")\":1,\"(\\\"p3\\\", \\\"c7\\\", \\\"b100\\\")\":2}"
MethodError: Cannot `convert` an object of type Char to an object of type String
Closest candidates are:
convert(::Type{String}, ::String) at essentials.jl:210
convert(::Type{T}, ::T) where T<:AbstractString at strings/basic.jl:231
convert(::Type{T}, ::AbstractString) where T<:AbstractString at strings/basic.jl:232
...
Stacktrace:
[1] setindex!(A::Vector{String}, x::Char, i1::Int64)
@ Base ./array.jl:839
[2] copyto!(dest::Vector{String}, src::String)
@ Base ./abstractarray.jl:846
[3] _collect
@ ./array.jl:563 [inlined]
[4] collect
@ ./array.jl:561 [inlined]
[5] _totuple
@ ./tuple.jl:329 [inlined]
[6] Tuple
@ ./tuple.jl:303 [inlined]
[7] #construct#1
@ ~/.julia/packages/StructTypes/NJXhA/src/StructTypes.jl:310 [inlined]
[8] construct
@ ~/.julia/packages/StructTypes/NJXhA/src/StructTypes.jl:310 [inlined]
[9] keyvalue
@ ~/.julia/packages/JSON3/PgKj8/src/structs.jl:282 [inlined]
[10] #read#36
@ ~/.julia/packages/JSON3/PgKj8/src/structs.jl:328 [inlined]
[11] read
@ ~/.julia/packages/JSON3/PgKj8/src/structs.jl:291 [inlined]
[12] #read#35
@ ~/.julia/packages/JSON3/PgKj8/src/structs.jl:288 [inlined]
[13] read
@ ~/.julia/packages/JSON3/PgKj8/src/structs.jl:288 [inlined]
[14] read(str::String, ::Type{Dict{Tuple{Vararg{String, N} where N}, Int64}}; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 ~/.julia/packages/JSON3/PgKj8/src/structs.jl:34
[15] read(str::String, ::Type{Dict{Tuple{Vararg{String, N} where N}, Int64}})
@ JSON3 ~/.julia/packages/JSON3/PgKj8/src/structs.jl:33
[16] top-level scope
@ In[125]:4
[17] eval
@ ./boot.jl:360 [inlined]
[18] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1094