How to bundle data (eg, JSON) in a hex dependency

Sure can, and its quite a common pattern. The function Application.app_dir/1 or Application.app_dir/2 will help. Using your example:

content =
  :my_app
  |> Application.app_dir("data")
  |> Path.join("tlds.json")
  |> File.read!()
  |> Jason.decode!()

Here :my_app is the name of your library app.

3 Likes