Normalizes caller data into collision-free JSON-native values.
Atom keys are accepted as an Elixir convenience and converted to strings at every depth. Structs, other key types, duplicate normalized keys, PIDs, references, tuples, and non-finite numbers are rejected before they reach a compiler port or artifact.
This is an input-boundary helper. It never creates atoms from caller data.
Example
iex> Letterpress.JSON.normalize_object(%{user: %{name: "Ada"}, active: true})
{:ok, %{"active" => true, "user" => %{"name" => "Ada"}}}
Summary
Functions
Normalizes a map with atom or string keys into a JSON object.
Functions
Normalizes a map with atom or string keys into a JSON object.
The entire nested value must be JSON-compatible. Any invalid key or value
returns {:error, :invalid_json_object}.
Examples
iex> Letterpress.JSON.normalize_object(%{"items" => [1, nil, false]})
{:ok, %{"items" => [1, nil, false]}}
iex> Letterpress.JSON.normalize_object(%{"pid" => self()})
{:error, :invalid_json_object}