ToonEx.OrderedObject (toon_ex v1.3.1)

Copy Markdown View Source

A TOON object that preserves the order of its keys.

Elixir maps with 32 or fewer keys are stored in sorted order, so the encoder cannot recover the original insertion order from a plain map. Wrap your key-value pairs in a %ToonEx.OrderedObject{} (or use ToonEx.OrderedObject.new/1) to control the order in which fields are emitted.

Example

iex> obj = ToonEx.OrderedObject.new([{"id", 123}, {"name", "Ada"}, {"active", true}])
iex> ToonEx.encode!(obj)
"id: 123\nname: Ada\nactive: true"

Nested objects, tabular arrays, and keyed tabular objects all preserve the order declared by the wrapping OrderedObject.

Summary

Functions

Creates an ordered object from a list of key-value pairs.

Types

t()

@type t() :: %ToonEx.OrderedObject{values: [{String.t(), term()}]}

Functions

new(values)

@spec new([{String.t(), term()}]) :: t()

Creates an ordered object from a list of key-value pairs.