Kiq v0.6.0 Kiq.Encoder View Source

This module wraps Jason.encode/1 to provide consistent and safe JSON encoding.

Typically this module shouldn’t be used outside of Kiq, but the function is documented for reference on how job arguments are encoded.

Link to this section Summary

Functions

Safely encode terms into JSON, if possible

Link to this section Functions

Safely encode terms into JSON, if possible.

Some Elixir/Erlang types can’t be represented as JSON. To make encoding as reliable as possible the encode/1 function attempts to convert incompatible terms into JSON friendly values.

The following sanitization is applied (recursively):

  • struct - Converted to a map using Map.from_struct/1
  • tuple — Converted to a list
  • pid, port, reference — Converted to a string using inspect, i.e. “#PID<0.101.0>“