JSV.Codec (jsv v0.5.1)

View Source

JSON encoder/decoder based on available implementation.

First looks for Jason, then Poision, then JSON (available since Elixir 1.18).

Summary

Functions

Returns the module used for JSON encoding and decoding.

Equivalent to JSON.decode/1.

Equivalent to JSON.decode!/1.

Equivalent to JSON.encode!/1.

Equivalent to JSON.encode!/1 with map keys ordered according to the sorter function.

Types

key()

@type key() :: binary() | atom()

key_sorter()

@type key_sorter() :: (key(), key() -> boolean())

Functions

codec()

@spec codec() :: module()

Returns the module used for JSON encoding and decoding.

decode(json)

@spec decode(binary()) :: {:ok, term()} | {:error, term()}

Equivalent to JSON.decode/1.

decode!(json)

@spec decode!(binary()) :: term()

Equivalent to JSON.decode!/1.

encode!(term)

@spec encode!(term()) :: binary()

Equivalent to JSON.encode!/1.

encode_to_iodata!(term)

@spec encode_to_iodata!(term()) :: iodata()

Equivalent to JSON.encode_to_iodata!/1.

format!(term)

@spec format!(term()) :: binary()

Equivalent to JSON.encode_to_iodata!/1.

format_ordered!(term, key_sorter)

@spec format_ordered!(term(), key_sorter()) :: binary()

Equivalent to JSON.encode!/1 with map keys ordered according to the sorter function.

The sorter function will be called with two keys from the same map and should return true if the first argument precedes or is in the same place as the second one.

Does not currently support structs and requires Jason.

format_ordered_to_iodata!(term, key_sorter)

@spec format_ordered_to_iodata!(term(), key_sorter()) :: iodata()

Like format_ordered!/1

format_to_iodata!(term)

@spec format_to_iodata!(term()) :: binary()

Equivalent to JSON.encode_to_iodata!/1.