# How to write data to file with JSON.jl?

**URL:** <https://discourse.julialang.org/t/how-to-write-data-to-file-with-json-jl/2993>\
**Category:** Data\
**Tags:** question, json\
**Created:** [March 31, 2017, 7:03pm UTC](https://discourse.julialang.org/t/how-to-write-data-to-file-with-json-jl/2993 "2017-03-31T19:03:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [March 31, 2017, 7:39pm UTC](https://discourse.julialang.org/t/how-to-write-data-to-file-with-json-jl/2993/2 "2017-03-31T19:39:39Z")

</div>

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:

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

```

or with:

```julia
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](https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh)) or editor mode to see the content formatted.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-write-data-to-file-with-json-jl/2993)._
