View Source simdjson (simdjsone v0.4.2)

Fast decoding of JSON using simdjson C++ library.

By default JSON decoder uses the atom null to represent JSON nulls. To modify this behavior, set the following configuration option to another atom value (e.g. nil for Elixir):

   {simdjsone, [{null, nil}]}.

See also https://github.com/simdjson/simdjson

Link to this section Summary

Functions

Decode a JSON string or binary to a term representation of JSON.

Decode a JSON string or binary to a term representation of JSON.

Encode a term to a JSON string.

Find a given Path (which must start with a slash) in the JSON resource. The resource reference must have been previously created by calling parse/1,2.

Find a given Path (which must start with a slash) in the JSON resource. The resource reference must have been previously created by calling parse/1,2.

Fast integer to binary conversion

Minify a JSON string or binary.

Parse a JSON string or binary and save it in a resource for later access by get/2. Returns a resource reference owned by the calling pid.

Link to this section Types

-type decode_opt() :: return_maps | object_as_tuple | dedupe_keys | use_nil | {null_term, atom()}.
-type decode_opts() :: [decode_opt()].

Decode options:

  • return_maps - decode JSON object as map
  • object_as_tuple - decode JSON object as a proplist wrapped in a tuple
  • dedup_keys - eliminate duplicate keys from a JSON object
  • use_nil - decode JSON "null" as nil
  • {null_term, V} - use the given value V for a JSON "null"
-type encode_opt() ::
    uescape | pretty | force_utf8 | use_nil | escape_forward_slashes |
    {bytes_per_red, non_neg_integer()}.
-type encode_opts() :: [encode_opt()].

Encode options:

  • uescape - escape UTF-8 sequences to produce a 7-bit clean output
  • pretty - return JSON using two-space indentation
  • use_nil - encode the atom nil as null`</li> <li>`escape_fwd_slash - escape the / character (useful when encoding URLs)
  • {bytes_per_red, N} - where N >= 0 - This controls the number of bytes that Jiffy will process as an equivalent to a reduction. Each 20 reductions we consume 1% of our allocated time slice for the current process. When the Erlang VM indicates we need to return from the NIF.

Link to this section Functions

-spec decode(binary() | list() | reference()) -> term().

Decode a JSON string or binary to a term representation of JSON.

-spec decode(binary() | list() | reference(), decode_opts()) -> term().

Decode a JSON string or binary to a term representation of JSON.

-spec encode(term()) -> iodata().

Encode a term to a JSON string.

-spec encode(term(), encode_opts()) -> iodata().
-spec get(reference(), binary()) -> term().

Find a given Path (which must start with a slash) in the JSON resource. The resource reference must have been previously created by calling parse/1,2.

-spec get(reference(), binary(), decode_opts()) -> term().

Find a given Path (which must start with a slash) in the JSON resource. The resource reference must have been previously created by calling parse/1,2.

-spec int_to_bin(integer()) -> binary().

Fast integer to binary conversion

-spec minify(binary() | list()) -> {ok, binary()} | {error, binary()}.

Minify a JSON string or binary.

-spec parse(binary()) -> reference().

Parse a JSON string or binary and save it in a resource for later access by get/2. Returns a resource reference owned by the calling pid.