JQ (Helix v0.1.5)
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 \\ [])
Execute a jq query on an elixir structure.
payload
is any elixir structurequery
a jq query as a string Internally this function encodes thepayload
into JSON, writes the JSON to a temporary file, invokes the jq executable on the temporary file with the supplied jqquery
. 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 tonil
.
error-reasons
Error reasons
JQ.MaxByteSizeExceededException
- when the byte_size of the encoded elixir structure is greater than the:max_byte_size
valueJQ.SystemCmdException
- when System.cmd/3 returns a non zero exit codeJQ.NoResultException
- when no result was returnedJQ.UnknownException
- when System.cmd/3 returns any other error besides those already handledPoison.EncodeError
- when there is an error encodingpayload
Poison.DecodeError
- when there is an error decoding the jq query resultTemp.Error
- when there is an error creating a temporary fileFile.Error
- when there is an error removing a temporary file