UndefVarError: writeshortest not defined with JSON3

Hi,
I use below code to write json file but it shows UndefVarError: writeshortest not defined. Please help me solve this problem! Thank you!

h5open(solution, "r") do f
    t = open_dataset(f, "t")[:]
    v = open_dataset(f, "v")
    maxv_l = similar(t)
    maxv_r = similar(t)
    @showprogress "Iterating max velocity" for i ∈ range(1, length=length(t))
        v_tmp = v[:,:,i]
        maxv_l[i] = maximum(v_tmp[patch_l])
        maxv_r[i] = maximum(v_tmp[patch_r])
    end

    content = Dict(
        :t => t,
        :maxv_l => maxv_l,
        :maxv_r => maxv_r,
    )
    open(catalog, "w") do io
        JSON3.write(io, content)
    end

The error is below,

UndefVarError: writeshortest not defined

Stacktrace:
[1] getproperty
@ .\Base.jl:35 [inlined]
[2] write(::StructTypes.NumberType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Float64; allow_inf::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:236
[3] write
@ C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:225 [inlined]
[4] write(::StructTypes.ArrayType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Vector{Float64}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:169
[5] write(::StructTypes.ArrayType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Vector{Float64})
@ JSON3 C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:165
[6] write(::StructTypes.DictType, buf::Vector{UInt8}, pos::Int64, len::Int64, x::Dict{Symbol, Vector{Float64}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:155
[7] write
@ C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:146 [inlined]
[8] write(io::IOStream, obj::Dict{Symbol, Vector{Float64}}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ JSON3 C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:32
[9] write
@ C:\Users\student.julia\packages\JSON3\GoF7x\src\write.jl:30 [inlined]
[10] #266
@ .\In[29]:31 [inlined]
[11] open(::var"#266#268"{Dict{Symbol, Vector{Float64}}}, ::String, ::Vararg{String}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Base .\io.jl:330
[12] open(::Function, ::String, ::String)
@ Base .\io.jl:328
[13] (::var"#265#267")(f::HDF5.File)
@ Main .\In[29]:30
[14] h5open(::var"#265#267", ::String, ::Vararg{String}; swmr::Bool, pv::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ HDF5 C:\Users\student.julia\packages\HDF5\I9NLZ\src\HDF5.jl:303
[15] h5open(::Function, ::String, ::String)
@ HDF5 C:\Users\student.julia\packages\HDF5\I9NLZ\src\HDF5.jl:301
[16] top-level scope
@ In[29]:14
[17] eval
@ .\boot.jl:373 [inlined]
[18] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1196

Probably a Parsers versioning issue, what’s your st and st -m? Also do you get the same issue when writing a simpler file (in other words, can you make your code snippet a self contained MWE by just writing out some dummy data)?

Hi nilshg,

My complete code is like this.

begin
    using PyCall, PyPlot, Oetqf, JSON3, JLD2, ProgressMeter
    include(joinpath(@__DIR__, "utils.jl"))
end

solution = joinpath(@__DIR__, "output.h5")
catalog = joinpath(@__DIR__, "catalog.json")

mf = load(joinpath(@__DIR__, "mesh.jld2"), "fault")
patch_l = (@. -485e3 .≤ mf.x .≤ -85e3) .* (@. -17.5e3 .≤ mf.z .≤ -2.5e3)'
patch_r = (@. 85e3 .≤ mf.x .≤ 485e3) .* (@. -17.5e3 .≤ mf.z .≤ -2.5e3)'
μ = 30e9

h5open(solution, "r") do f
    t = open_dataset(f, "t")[:]
    v = open_dataset(f, "v")
    maxv_l = similar(t)
    maxv_r = similar(t)
    @showprogress "Iterating max velocity" for i ∈ range(1, length=length(t))
        v_tmp = v[:,:,i]
        maxv_l[i] = maximum(v_tmp[patch_l])
        maxv_r[i] = maximum(v_tmp[patch_r])
    end

    content = Dict(
        :t => t,
        :maxv_l => maxv_l,
        :maxv_r => maxv_r,
    )
    open(catalog, "w") do io
        JSON3.write(io, content)
    end

t is time parameter. I think it’s not the problem of JSON3. Could be read and write data into “content” dictionary. Can you help me optimize this?

But your stacktrace explicitly points to write, and these writeshortest errors pop up frequently (I’ve seen them loads in CSV.jl) when there’s a version mismatch.

Therefor I will repeat my questions:

  • What is your st and st -m?
  • Can you write out something simple like JSON3.write("test.json", (x = rand('a':'z', 100), y = rand(100)))

My string is data like this:

Dict(:maxv_r => [1.0147133434804667e-9, 1.796118473731384e-9, 7.57657124507717e-9, 1.0231846445183663e-8, 1.1349013697680884e-8, 1.3167898562992613e-8, 1.49972231762508e-8, 1.4435121588935785e-8, 1.3176734564674757e-8, 1.2394497977361867e-8, 1.1686529120019848e-8, 1.1186273697127198e-8, 1.0954811066070923e-8, 1.081808008533313e-8, 1.0769229656071547e-8, 1.0756597593374443e-8, 1.0752271415084019e-8, 1.0750580284202741e-8, 1.0749215131461214e-8, 1.0747894234025832e-8, 1.0746321796440239e-8, 1.0744949619617457e-8, 1.0743867673829676e-8, … 7.598747648583915e8, 7.598747863885643e8, 7.598748000376701e8, 7.598748077412821e8, 7.598748131626374e8, 7.598748172228965e8, 7.598748206474913e8, 7.598748236435429e8, 7.598748260265518e8, 7.598748300485772e8, 7.598748323579266e8])
I am not sure how to know my st -m.
And if I do dummy data like below, there is no error.

people = [Dict(“name”=>“CoolGuy”, “company”=>“tech”) for i=1:1000]
companies = [Dict(“name”=>“CoolTech”, “address”=>“Bay Area”) for i=1:100]
data = Dict(“people”=>people, “companies”=>companies)

open(catalog,“w”) do f
JSON3.write(f, data)
end