How to write data to file with JSON.jl?

You take data, transform it into a string (JSON formatted) and then transform this string into a quoted string when writing to a file. Instead, you should format only once, either with:

open("foo.json","w") do f 
    write(f, json_string) 
end

or with:

open("foo.json","w") do f
    JSON.print(f, data)
end

As for formatting, I’d just use a browser extension (e.g. for Google Chrome) or editor mode to see the content formatted.

11 Likes