Tiny v1.0.0 Tiny

This module contains the entirely of the Tiny project. There are interface functions for encoding and decoding JSON, and little else.

Both encoding and decoding are done per the JSON specification with direct mapping between JSON types and Elixir types:


JSON TypeElixir Type
ArrayList
Booleantrue or false
ObjectMap
NumberInteger or Float
StringBinary
nullnil

Numbers are parsed into Integer types when possible, falling back to Floats when required. This is due to functions which operate differently based on the numeric typing.

Summary

Functions

Safely decodes a JSON input binary to an Elixir term

Decodes a JSON inout binary to an Elixir term

Safely encodes a JSON compatible value to iodata or a binary

Encdoes a JSON compatible value to iodata or a binary

Types

json()
json() :: atom | binary | list | map | number

Functions

decode(bin, opts \\ [])
decode(binary, Keyword.t) :: {:ok, json} | {:error, atom}

Safely decodes a JSON input binary to an Elixir term.

Parsing errors are caught and an :error Tuple is returned. Any successful values are wrapped in an :ok Tuple.

decode!(bin, opts \\ [])
decode!(binary, Keyword.t) :: json | no_return

Decodes a JSON inout binary to an Elixir term.

Rather than return Tuples, this function will raise ArgumentError on invalid inputs. No information is provided beyond the error, so log context as needed.

encode(val, opts \\ [])
encode(json, Keyword.t) ::
  {:ok, binary | iodata} |
  {:error, atom}

Safely encodes a JSON compatible value to iodata or a binary.

Parsing errors are caught and an :error Tuple is returned. Any successful values are wrapped in an :ok Tuple.

encode!(val, opts \\ [])
encode!(json, Keyword.t) :: binary | iodata | no_return

Encdoes a JSON compatible value to iodata or a binary.

Rather than return Tuples, this function will raise ArgumentError on invalid inputs. No information is provided beyond the error, so log context as needed.