We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When I save into a json file a Dict which contains a Dict as a key, the key is replaced by a string.
Here is an example: d = Dict{Dict{String, Int}, Int}(Dict("v1" => 1) => 2)
d = Dict{Dict{String, Int}, Int}(Dict("v1" => 1) => 2)
I save variable d using
d
julia> open("test.json", "w") do f JSON.print(f, d, 4) end
The problem is that I get the following json file:
{ "Dict(\"v1\" => 1)": 2 }
and when I read the file, due to the quotation marks, Dict(\"v1\" => 1) is considered to be a String rather than a Dict{String, Int}:
Dict(\"v1\" => 1)
julia> sData = join(readlines("test.json")) julia> dExtracted = JSON.parse(sData) Dict{String,Any} with 1 entry: "Dict(\"v1\" => 1)" => 2
Can I write and read in json a Dict which has a Dict as keys?
The text was updated successfully, but these errors were encountered:
After some reading, I found that the name of an object in json is necessarily a string.
I replaced the type Dict{Dict{String, Int} by Vector{Vector{Any}} which is not completely satisfactory but works.
Dict{Dict{String, Int}
Vector{Vector{Any}}
Sorry, something went wrong.
Personally I think JSON.jl should error on such keys and not just naively stringify them.
That would have saved me some debugging and reading ^^'.
No branches or pull requests
When I save into a json file a Dict which contains a Dict as a key, the key is replaced by a string.
Here is an example:
d = Dict{Dict{String, Int}, Int}(Dict("v1" => 1) => 2)
I save variable
d
usingThe problem is that I get the following json file:
and when I read the file, due to the quotation marks,
Dict(\"v1\" => 1)
is considered to be a String rather than a Dict{String, Int}:Can I write and read in json a Dict which has a Dict as keys?
The text was updated successfully, but these errors were encountered: