jq v1.0.2 JQ View Source

Provides capability to run jq queries on elixir structures. jq docs

Examples

iex> JQ.query(%{key: "value"}, ".key")
{:ok, "value"}

iex> JQ.query!(%{key: "value"}, ".key")
"value"

Link to this section Summary

Functions

Execute a jq query on an elixir structure

Execute a jq query on an elixir structure

Link to this section Functions

Link to this function

query(payload, query, options \\ []) View Source
query(any(), String.t(), list()) ::
  {:ok, any()} | {:error, :cmd | :unknown | :max_byte_size_exceeded}

Execute a jq query on an elixir structure.

Internally invokes JQ.query!/3 and rescues from all exceptions.

If a JQ.NoResultException is raised, {:ok, nil} is returned

Link to this function

query!(payload, query, options \\ []) View Source
query!(any(), String.t(), list()) :: any()

Execute a jq query on an elixir structure.

  • payload is any elixir structure
  • query a jq query as a string

Internally this function encodes the payload into JSON, writes the JSON to a temporary file, invokes the jq executable on the temporary file with the supplied jq query.

The result is then decoded from JSON back into an elixir structure. The temporary file is removed, regardless of the outcome. System.cmd/3 is called with the :stderr_to_stdout option.

Options

  • :max_byte_size - integer representing the maximum number of bytes allowed for the payload, defaults to nil.

Error reasons