OctaStar.JSON (octa_star v0.2.0)

Copy Markdown

Tiny wrapper around Erlang/OTP's native :json module.

Erlang represents JSON null as the atom :null, while Elixir callers expect nil. This module converts nil to :null before encoding and converts decoded :null values back to nil.

Summary

Functions

Decodes JSON into Elixir terms.

Decodes JSON into Elixir terms, raising on invalid JSON.

Encodes an Elixir term as JSON.

Functions

decode(json)

@spec decode(String.t()) :: {:ok, term()} | {:error, term()}

Decodes JSON into Elixir terms.

decode!(json)

@spec decode!(String.t()) :: term()

Decodes JSON into Elixir terms, raising on invalid JSON.

encode!(term)

@spec encode!(term()) :: String.t()

Encodes an Elixir term as JSON.