How can I Jason.encode a computed field?

In my Abinsthe schema, I have a field resolver which creates an AWS signed link. The problem with this approach is that I can’t reuse it elsewhere. For example, I need that url field when I query the data via Ecto to store that json data in S3. I suspect it’s a combination between virtual fields, computed fields, and using the Jason encoder, but I am not really sure how all those tie together. Could someone help me with this?

For example, my schema is like so:

  @derive {
    only: [

  embedded_schema do
    field :name, :string
    field :last_modified, :naive_datetime
    field :size, :integer
    field :mime_type, :string

I then query everything and preload everything before running it through Jason.encode!. How can I have Jason.encode create a url field which computes a signed url?

I suspect you will need to implement an encoder for your struct. There’s a reasonable example at Jason.Encoder — jason v1.3.0 and quite a lot of discussion here: Adding calculated fields to Ecto Schema - virtual field or?