OpenUI.JSON (OpenUI v0.1.1)

Copy Markdown View Source

JSON on top of Elixir's JSON that keeps the key order of objects.

Objects decode to OpenUI.JSON.Object. Plain maps still encode, in map order.

Summary

Functions

Decodes binary, returning objects as OpenUI.JSON.Object.

Like decode/1, but raises on invalid JSON.

Encodes term. With pretty: true, indents with two spaces and ends with a newline.

Builds an ordered object from key-value pairs.

Replaces every OpenUI.JSON.Object with a plain map, recursively.

Functions

decode(binary)

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

Decodes binary, returning objects as OpenUI.JSON.Object.

decode!(binary)

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

Like decode/1, but raises on invalid JSON.

encode!(term, opts \\ [])

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

Encodes term. With pretty: true, indents with two spaces and ends with a newline.

object(pairs)

@spec object([{String.t(), term()}]) :: OpenUI.JSON.Object.t()

Builds an ordered object from key-value pairs.

to_plain(list)

@spec to_plain(term()) :: term()

Replaces every OpenUI.JSON.Object with a plain map, recursively.