The most correct way to read a JSON file

What is most correct way to open, read and parse JSON file with poison?

For example if we have example.json file in root of some project.

Is it?

def get_json(filename) do
    # ....
end

P.S Sorry for question i’m :eggplant: in Elixir

1 Like

I’m not sure if it’s the correct way, but I would do something like this

defmodule Test do
  def get_json(filename) do
    with {:ok, body} <- File.read(filename),
         {:ok, json} <- Poison.decode(body), do: {:ok, json}
  end
end
17 Likes

Me too, but looks nice. Thank you!

1 Like