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

Can't serialize empty NamedTuple #279

Closed
cchderrick opened this issue Mar 19, 2019 · 0 comments · Fixed by #293
Closed

Can't serialize empty NamedTuple #279

cchderrick opened this issue Mar 19, 2019 · 0 comments · Fixed by #293

Comments

@cchderrick
Copy link

I am using JSON v0.20.0 on Julia Version 1.0.3
Code to reproduce:

x = NamedTuple()
y = (a=1,b=2)
julia> typeof(x)
NamedTuple{(),Tuple{}}

julia> typeof(y)
NamedTuple{(:a, :b),Tuple{Int64,Int64}}

Correctly serialize stuffed NamedTuple.

julia> JSON.json(y)
"{\"a\":1,\"b\":2}"

Expecting empty NamedTuple serialized to an empty object.

julia> JSON.json(x)
"{}"

But got this:

julia> JSON.json(x)
ERROR: Cannot serialize type NamedTuple{(),Tuple{}}
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] lower(::NamedTuple{(),Tuple{}}) at .\.julia\packages\JSON\ebvl3\src\Writer.jl:47
 [3] show_json(::JSON.Writer.CompactContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::JSON.Serializations.StandardSerialization, ::NamedTuple{(),Tuple{}}) at .\.julia\packages\JSON\ebvl3\src\Writer.jl:314
 [4] #show_json#3(::Nothing, ::Function, ::Base.GenericIOBuffer{Array{UInt8,1}}, ::JSON.Serializations.StandardSerialization, ::NamedTuple{(),Tuple{}}) at .\.julia\packages\JSON\ebvl3\src\Writer.jl:325
 [5] show_json(::Base.GenericIOBuffer{Array{UInt8,1}}, ::JSON.Serializations.StandardSerialization, ::NamedTuple{(),Tuple{}}) at .\.julia\packages\JSON\ebvl3\src\Writer.jl:324
 [6] print(::Base.GenericIOBuffer{Array{UInt8,1}}, ::NamedTuple{(),Tuple{}}) at .\.julia\packages\JSON\ebvl3\src\Writer.jl:349
 [7] #sprint#324(::Nothing, ::Int64, ::Function, ::Function, ::NamedTuple{(),Tuple{}}) at .\strings\io.jl:101
 [8] sprint(::Function, ::NamedTuple{(),Tuple{}}) at .\strings\io.jl:97
 [9] json(::NamedTuple{(),Tuple{}}) at .\.julia\packages\JSON\ebvl3\src\Writer.jl:354
 [10] top-level scope at none:0
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

Successfully merging a pull request may close this issue.

1 participant