How can I use Jason instead of Poison

I have an old codebase where I want to delete some of the json renderers in favor of automatic rendering via json encoders.

I have tried to add Jason.Encoder like this:

@derive {Jason.Encoder, only: [:id, :description]} 
schema "items" do

But I get an error like cannot encode metadata from the :__meta__ field with some suggestion to use @derive {Poison.Encoder, only: [:name, :title, ...]}

If I use the Poison encoder instead of Jason, all works fine BUT, I don’t understand why Jason isn’t working.

I’m on phoenix 1.4.1 so, I expected that since Jason is the default encoder, it should work.

Any idea of what would I need to do in order for Jason to work?

Maybe the config.exs file?

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason


I had

config :phoenix, :generators,
  migration: true,
  binary_id: false, 
  json_library: Jason

config :phoenix, :json_library, Jason
solved the issue. Thanks, Mike!


Anyone know if this changes with Elixir 1.9?

1 Like