I have done the following is there a better way to do this?:
File.write("../hello", Poison.encode!(some_stuff))
Click on the ‘ Import JSON File ‘ button: Locate your JSON file. In our case, locate the Product_List file, and then click on Open: Press on the ‘ Convert JSON to TXT ‘ button:
Write a data in file using JSON use json.dump () or json.dumps () used. write like this to store data in file. this example in list is store to a file. This does the same thing as @phihag's answer, but is not guaranteed to work at all times. Consider such code: f = open ('1.txt', 'w'); f.write ('a'); input ().
The Elixir JSON library is available under the BSD 3-Clause aka "BSD New" license Built using ExDoc(v0.23.0) for the Elixir programming language. Designed by Friedel Ziegelmayer.
Elixir JSON This library provides a natively implemented JSON encoder and decoder for Elixir. You can find the package in hex.pmand the documentation in hexdocs.pm. All contributions are welcome! Installing Simply add {:json, "~> 1.4"}to your project's mix.exsand run mix deps.get. Usage Encoding an Elixir type
You are missing the third argument, the mode options. Something like this would work:
File.write("../hello", Poison.encode!(some_stuff), [:binary])
Other than the missing argument, what you have is a line of code that easy to understand. With your use of encode!
an exception will be raised if the encoding fails. If you want to ensure the file is written successfully without checking the return value from File.write/3
you should use File.write!/3
. Using File.write!/3
fits better with Erlang's "let it crash" philosophy (http://learnyousomeerlang.com/errors-and-exceptions). Though it all depends on the context of this line...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With