Behaviour for the JSON library used to encode request bodies and decode API responses.
By default the client uses ApifyClient.JSON.Native, which delegates to
Elixir's built-in JSON module, so no extra dependency is required.
Configuration
Set the adapter for every client in your application config:
config :apify_client, :json_library, ApifyClient.JSON.Jasonor for a single call:
ApifyClient.Actors.start("apify/web-scraper", input, json_library: MyApp.ApifyJSON)Built-in adapters
ApifyClient.JSON.Native- Elixir's built-inJSON(default)ApifyClient.JSON.Jason- Jason, available when:jasonis a dependency of your application
Custom adapters
defmodule MyApp.ApifyJSON do
@behaviour ApifyClient.JSON
@impl ApifyClient.JSON
def encode_to_iodata!(term), do: MyJSON.encode_to_iodata!(term)
@impl ApifyClient.JSON
def decode(binary), do: MyJSON.decode(binary)
end
Summary
Functions
Returns the adapter configured under config :apify_client, :json_library,
falling back to ApifyClient.JSON.Native.
Encodes term to a JSON binary with the given adapter.
Callbacks
@callback decode(binary()) :: {:ok, term()} | {:error, Exception.t()}
Decodes a JSON binary.
Returns {:ok, term} on success or {:error, exception} on failure.
Encodes term as JSON. Raises if the term cannot be encoded.
Functions
@spec default_adapter() :: module()
Returns the adapter configured under config :apify_client, :json_library,
falling back to ApifyClient.JSON.Native.
Encodes term to a JSON binary with the given adapter.