View Source StableJason.Encoder (stable_jason v2.0.0)

Utilities for encoding Elixir values to a deterministic or stable JSON.

Summary

Functions

Generates stable JSON corresponding to input using %Jason.OrderedObject{} from Jason.

Functions

Link to this function

encode(input, sorter \\ :asc)

View Source

Generates stable JSON corresponding to input using %Jason.OrderedObject{} from Jason.

Example

iex> StableJason.Encoder.encode(%{c: 3, b: 2, a: 1})
{:ok, %Jason.OrderedObject{values: [{"a", 1}, {"b", 2}, {"c", 3}]}}

iex> StableJason.Encoder.encode(<<0::1>>)
{:error,
  %Protocol.UndefinedError{
    protocol: Jason.Encoder,
    value: <<0::size(1)>>,
    description: "cannot encode a bitstring to JSON"
  }}