Translates Ash records into JSON-friendly payloads, extracting explicitly exposed metadata and stripping internal fields.
Type Coercion
During serialization, some Erlang/Elixir specific types are safely coerced for JSON:
- Tuples are converted to lists (e.g.,
{:ok, val}becomes["ok", val]). - Atoms (other than
true,false, andnil) are converted to strings. - Date/Time structs (
DateTime,NaiveDateTime,Date,Time) are ISO8601 formatted. - Ash not-loaded fields and forbidden fields are omitted from the output.
can_*permission fields are extracted and returned as metadata.
See Alva.Registry.public_fields/1 for how public fields are determined.
Summary
Functions
Serializes a record or list of records.
Recursively strips Ash metadata, removes forbidden or unloaded fields, and converts Elixir types (Date, Time, DateTime, atoms, tuples) to JSON-safe representations.
Functions
Serializes a record or list of records.
Returns a tuple {stripped_payload, exposed_metadata}.
Options
:expose_metadata(list of atoms) - Keys to extract from__metadata__and return alongside the payload.
Recursively strips Ash metadata, removes forbidden or unloaded fields, and converts Elixir types (Date, Time, DateTime, atoms, tuples) to JSON-safe representations.