Write and read json file

I tried to save and read the following json file, but there is some problem for the presence of nothing.

using YFinance, JSON3
aapl_json=get_quoteSummary("AAPL")

aapl_json_string=string(aapl_json)
open("aapl.json", "w") do f
     write(f, aapl_json_string)
end

aapl_json_string=open("aapl.json", "r") do f
   read(f,String)
end

julia> aapl_json =  JSON3.read(aapl_json_string);
ERROR: ArgumentError: invalid JSON at byte position 4217 while parsing type Nothing: InvalidChar
                  "fmt": nothing,

What is the correct way to save to be able to reload the file in these cases?

julia> using YFinance, JSON3
julia> aapl_json=get_quoteSummary("AAPL")

julia> open("aapl.json", "w") do f
            JSON3.write(f, aapl_json)
       end

julia> aapl_json_in=open("aapl.json", "r") do f
          JSON3.read(f)
       end
1 Like