JQ (Helix v0.1.6-rc)

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

examples

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. Internally invokes JQ.query!/3 and rescues from all exceptions. If a JQ.NoResultException is raised, {:ok, nil} is returned

Execute a jq query on an elixir structure.

Link to this section Functions

Link to this function

query(payload, query, options \\ [])

@spec 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 \\ [])

@spec 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

Options

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

error-reasons

Error reasons

  • JQ.MaxByteSizeExceededException - when the byte_size of the encoded elixir structure is greater than the :max_byte_size value
  • JQ.SystemCmdException - when System.cmd/3 returns a non zero exit code
  • JQ.NoResultException - when no result was returned
  • JQ.UnknownException - when System.cmd/3 returns any other error besides those already handled
  • Poison.EncodeError - when there is an error encoding payload
  • Poison.DecodeError - when there is an error decoding the jq query result
  • Temp.Error - when there is an error creating a temporary file
  • File.Error - when there is an error removing a temporary file