Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Cannot JSON convert data arrays with NA #250

Open
disleyland opened this issue May 8, 2017 · 3 comments
Open

Cannot JSON convert data arrays with NA #250

disleyland opened this issue May 8, 2017 · 3 comments

Comments

@disleyland
Copy link

disleyland commented May 8, 2017

cannot JSON convert any data arrays with NA.

JSON.json(@DaTa [1,2,NA]) used to produce "[1,2,{}]" but now produces the error "Cannot serialize type DataArrays.NAtype"

guessing this is because the vector syntax {} is now discontinued

is there a workaround? or before converting do we have to manually convert all data arrays to nothing or "" ?

This issue was reported in JSON.jl.

@nalimilan
Copy link
Member

Hmm, serialization seems to work fine, so I'm not sure what's the problem. Will ask upstream.

using DataArrays
x=@data [1,2,NA]
io=IOBuffer()
serialize(io, x)
seekstart(io)
deserialize(io)

@TotalVerb
Copy link

As a workaround you can just write

try JSON.lower(NA) catch
    JSON.lower(::DataArrays.NAtype) = nothing
end

in your own code for now. This is type piracy and not a good long term solution, but the try/catch ensures that it will only add the definition if it doesn't already exist.

@ararslan
Copy link
Member

ararslan commented Jul 5, 2017

A slightly nicer (though basically equivalent) workaround:

if !applicable(JSON.lower, NA)
    JSON.lower(::NAtype) = nothing
end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants