View Source Jaqex (jaqex v0.1.2)

Documentation for Jaqex.

Summary

Functions

Filters the given JSON string with the given j(a)q code and loading .jq scripts in the given path.

Similar to filter/3 but raises on errors.

Similar to filter_file/3 but loads the json doc at the given path.

Similar to filter_file/3 but raises on errors.

Functions

filter(json_doc, code, path \\ "")

@spec filter(String.t(), String.t(), Path.t()) :: {:ok, term()} | {:error, term()}

Filters the given JSON string with the given j(a)q code and loading .jq scripts in the given path.

Examples

iex> Jaqex.filter("[1, 2, 3]", "[ .[] | {v: .} ]")
{:ok, [%{"v" => 1}, %{"v" => 2}, %{"v" => 3}]}

Assuming priv/ contains a jq script t.jq, the following demonstrates Jaqex loading that and availing it for use by your filter code:

iex> Jaqex.filter("[\"fooBar\"]", "import \"t\" as t; [ .[] | t::snake_case(.) ]", "priv")
{:ok, ["foo_bar"]}

filter!(json_doc, code, path \\ "")

@spec filter!(String.t(), String.t(), Path.t()) :: term()

Similar to filter/3 but raises on errors.

filter_file(fname, code, path \\ "")

@spec filter_file(Path.t(), String.t(), Path.t()) :: {:ok, term()} | {:error, term()}

Similar to filter_file/3 but loads the json doc at the given path.

filter_file!(fname, code, path \\ "")

@spec filter_file!(Path.t(), String.t(), Path.t()) :: term()

Similar to filter_file/3 but raises on errors.