Protocol for encoding values for LiveSvelte JSON serialization.
Transforms structs and other terms into JSON-compatible data (maps, lists,
primitives) before the configured JSON library encodes to a string. Supports
@derive with :only and :except to control which struct fields are
encoded. By default all keys except :__struct__ are encoded.
Deriving
@derive LiveSvelte.Encoder— encode all struct fields except:__struct__@derive {LiveSvelte.Encoder, only: [:a, :b]}— encode only listed keys@derive {LiveSvelte.Encoder, except: [:secret]}— encode all except listed keys
Example
defmodule User do
@derive {LiveSvelte.Encoder, except: [:password]}
defstruct [:name, :email, :password]
endFor structs you don't own, use Protocol.derive/3 outside the module.
Summary
Functions
Encodes a value to a JSON-compatible term (map, list, or primitive).