JSON3.jl
JSON3.jl copied to clipboard
Critical: Vector of Vector raise Exception
Hi there! I wanted to report an issue with the write function in the JSON3 library. When I tried to use it to translate a vector into a valid JSON string, I found that using an empty array as [] works correctly, but [[]] does not. Could the team please look into this issue and consider fixing it? It's a simple use case that is currently not functioning as expected. Thank you!
1. Example for empty vector: OK
using JSON3
julia> JSON3.write([])
"[]"
2. Example for an empty vector instead of another vector: Error
julia> JSON3.write([[]])
ERROR: BoundsError: attempt to access 2-element Vector{UInt8} at index [3]
Stacktrace:
[1] setindex!(A::Vector{UInt8}, x::UInt8, i1::Int64)
@ Base ./array.jl:966
[2] write(::StructTypes.ArrayType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Vector{Any}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 ~/.julia/packages/JSON3/CpNms/src/write.jl:71
[3] write(::StructTypes.ArrayType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Vector{Any})
@ JSON3 ~/.julia/packages/JSON3/CpNms/src/write.jl:165
[4] write(::StructTypes.ArrayType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Vector{Vector{Any}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 ~/.julia/packages/JSON3/CpNms/src/write.jl:170
[5] write
@ ~/.julia/packages/JSON3/CpNms/src/write.jl:165 [inlined]
[6] write(obj::Vector{Vector{Any}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 ~/.julia/packages/JSON3/CpNms/src/write.jl:39
[7] write(obj::Vector{Vector{Any}})
@ JSON3 ~/.julia/packages/JSON3/CpNms/src/write.jl:36
[8] top-level scope
@ REPL[3]:1