I’m running a somewhat long and slow iteration. I want to incrementally save the result of each iteration in a singular JSON file. The problem is that when the file is closed (because of early termination or because the loop is simply done), and I want to load the content of the JSON file (with
JSON.parsefile) the resulting object should be an Array of
Dicts. Is there any way of doing that…?
The rational is that in the same way you’d
push! the result from the iteration into some
Vector you’re collecting the results in (to later do what you will with), I’d like to “push” into a JSON file.
MWE that does not work:
x = rand(10) open("tmp.json", "a") do io for i in x y = sin(i) JSON.print(io, Dict(:k => i, :v => y), 3) end end