-
Notifications
You must be signed in to change notification settings - Fork 100
Description
Wanted to write some JSON files (as I wanted something more stable/compatible than "Serialization.jl", so went through this package.
Nowhere on the doc page am I actually told how to write something to a file. After looking through some cases where people used the package elsewhere, I found I could do:
using JSON
tmp = Dict(
:ab => 1.0,
:cd => 2.0,
:ef => 3.0
)
open("tmp.json","w") do f
JSON.print(f, tmp)
end
Now when I see this, I realise that this is probably what this section tells me:
JSON.print(io::IO, s::AbstractString)
JSON.print(io::IO, s::Union{Integer, AbstractFloat})
JSON.print(io::IO, n::Nothing)
JSON.print(io::IO, b::Bool)
JSON.print(io::IO, a::AbstractDict)
JSON.print(io::IO, v::AbstractVector)
JSON.print(io::IO, v::Array)
However, for someone not familiar with the technical aspects of I/O stuff, this is not very helpful. I tried having io::IO
be my file name. And then I filliped it thinking that maybe s::AbstractString
was the filename and io
what I wanted to write.
There is probably a good reason for why things are written like this, but I imagine that an additional section would be greatly helpful for people who don't spend much time thinking about this, and just want to e.g. put data in a file.