Skip to content

missing feature or unclear docs? #417

@lmiq

Description

@lmiq

Given that the JSON.json properly prints the serialized string, shouldn't the file creation just work? What am I missing?

julia> x = Dict{String,Dict{String,Float64}}("a" => Dict("a1" => 1))
Dict{String, Dict{String, Float64}} with 1 entry:
  "a" => Dict("a1"=>1.0)

julia> JSON.json(x)
"{\"a\":{\"a1\":1.0}}"

julia> JSON.json("test.dat", x)
ERROR: MethodError: no method matching JSON.Writer.PrettyContext(::IOBuffer, ::Dict{String, Dict{String, Float64}}, ::Int64, ::Bool, ::Set{UInt64}, ::Nothing)
The type `JSON.Writer.PrettyContext` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  JSON.Writer.PrettyContext(::T, ::Int64, ::Int64, ::Bool, ::Set{UInt64}, ::Any) where T<:IO
   @ JSON ~/.julia/packages/JSON/93Ea8/src/Writer.jl:102
  JSON.Writer.PrettyContext(::IO, ::Any, ::Any)
   @ JSON ~/.julia/packages/JSON/93Ea8/src/Writer.jl:109
  JSON.Writer.PrettyContext(::IO, ::Any)
   @ JSON ~/.julia/packages/JSON/93Ea8/src/Writer.jl:109
```

It appears that this should work from the docs here: https://juliaio.github.io/JSON.jl/stable/writing/#Core-JSON-Serialization-JSON.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions