Is there any convenient function in JSON or Dict or CSV to set the form with ‘””‘?
I mean “{“a”:[“a1″,”a2″]}” -> “{“”a””:[“”a1″”,””a2″”]}”, each of “a*” is enclosed by ‘””‘.
Because this JSON form string data could not read out in CSV without this enclosure.
What am doing:
using JSON,CSV,DataFrames
tf = "test.csv"
if !isfile(tf)
open(tf,"w") do f
println(f,string("index",",","data"))
end
end
dic = Dict("a"=>["a1","a2"])
j = JSON.json(dic)
open(tf,"a") do f
println(f, string(1,",",""$j"")) # <- ①
end
df = CSV.read(tf, DataFrame) # <- ②
at the ①, as you can imagine the file is
index,data
1,"{"a":["a1","a2"]}"
then df at ② shows
Row │ index data Column3
│ Int64 String1 String3
─────┼─────────────────────────
1 │ 1 { a2
of course my expectation is
Row │ index data
│ Int64 String31
─────┼──────────────────────────
1 │ 1 {"a":["a1","a2"]}
and shoud be the file
index,data
1,"{""a"":[""a1"",""a2""]}"
but as far as using JSON.json() simply, the file has only single “double quotation”.
Then return to my question, is there any simple way to put double “double quotation” instead of single “double quotation” in JSON.jl, Dict() or CSV.jl?
I am wondering there is a hidden argument in their functions.
5