Represents a JSON value.
Represents a JSON value for encoding. Just like a val()
, but also
accepts datetime tuples, atoms as strings and iodata as object
member names.
-type enc_val() :: val() | calendar:datetime() | enc_obj() | enc_str().
Represents a JSON object.
Represents a JSON array.
Represents a JSON number.
-type num() :: number().
Represents a JSON string.
-type str() :: binary().
When encoding, object member names can be atoms and iodata.
When encoding, atoms and binaries will be encoded as JSON strings.
-type enc_str() :: binary() | atom().
Options for encode/2
.
-type encode_opts() ::
#{
%% Set to `true` to encode without any whitespace.
compact => boolean()
%% Indent all rows with this whitespace.
, indent => iodata()
%% Print object members sorted by their name.
, sort_objects => boolean()
%% Timezone used in encoding of datetime values (default `utc`).
%% If a `TzStr` is used, it should be on the form "HH:MM", to
%% be RFC3339/ISO8601-compatible.
, tz => utc | local | OffsetMinutes :: integer() | TzStr :: iodata()
}.
-spec decode(binary()) -> {ok, val()}.
-spec decode(binary(), decode_opts()) -> {ok, val()}.
If Bin
does not contain valid JSON, decode/1
crashes.
-spec decode(binary()) -> {ok, val()}.
-spec decode(binary(), decode_opts()) -> {ok, val()}.
If Bin
does not contain valid JSON, decode/1
crashes.
-spec encode(enc_val()) -> iodata().
-spec encode(enc_val(), encode_opts()) -> iodata().
-spec encode(enc_val()) -> iodata().
-spec encode(enc_val(), encode_opts()) -> iodata().