Low-level encoding functions, compatible with Jason's Encode module.
These functions encode individual Elixir terms to JSON iodata.
They are designed for use inside custom RustyJson.Encoder protocol
implementations, providing the same API as Jason's Encode module.
Opts
Functions that accept opts use an opaque type matching Jason's Encode.opts().
The opts value is passed to RustyJson.Encoder.encode/2 implementations and
should be forwarded to Encode functions as-is.
Examples
defimpl RustyJson.Encoder, for: Money do
def encode(%{amount: a, currency: c}, opts) do
RustyJson.Encode.map(%{amount: a, currency: to_string(c)}, opts)
end
end
Summary
Functions
Encodes an atom to a JSON string or literal.
Encodes a float to a JSON number.
Encodes an integer to a JSON number.
Encodes a keyword list as an ordered JSON object.
Encodes a list to a JSON array.
Encodes a map to a JSON object.
Builds encoding options from an escape mode.
Encodes a string to a JSON string.
Encodes a struct to JSON.
Encodes any term to JSON iodata.
Types
@opaque opts()
Opaque encoding options.
Passed to RustyJson.Encoder.encode/2 implementations.
Forward to Encode functions as-is.
Functions
Encodes an atom to a JSON string or literal.
Encodes a float to a JSON number.
Encodes an integer to a JSON number.
Encodes a keyword list as an ordered JSON object.
Preserves key insertion order, matching Jason's Encode.keyword/2.
Encodes a list to a JSON array.
Encodes a map to a JSON object.
Builds encoding options from an escape mode.
Returns an opaque opts value that can be passed to value/2, map/2,
string/2, and other encoding functions.
Examples
opts = RustyJson.Encode.opts(:json)
RustyJson.Encode.string("hello", opts)
Encodes a string to a JSON string.
Encodes a struct to JSON.
Encodes any term to JSON iodata.
Dispatches based on type, matching Jason's Encode.value/2.