Warpath.Expression (Warpath v0.5.0) View Source

This module contains functions to compile a jsonpath query string.

Link to this section Summary

Functions

Compile a jsonpath string query

Compiles jsonpath string query to expression.

Link to this section Types

Specs

dot_access() :: {:dot, property()}

Specs

filter() ::
  {:filter,
   has_children() | {operator() | guard(), subpath_expression() | term()}}

Specs

guard() ::
  :is_atom
  | :is_binary
  | :is_boolean
  | :is_float
  | :is_integer
  | :is_list
  | :is_map
  | :is_nil
  | :is_number
  | :is_tuple

Specs

has_children() :: {:has_children?, subpath_expression()}

Specs

indexes() :: {:indexes, [{:index_access, integer()}, ...]}

Specs

operator() ::
  :< | :> | :<= | :>= | :== | :!= | :=== | :!== | :not | :and | :or | :in

Specs

property() :: {:property, String.t() | atom()}

Specs

root() :: {:root, String.t()}

Specs

scan() :: {:scan, property() | wildcard() | filter() | indexes()}

Specs

slice() ::
  {:slice,
   [start_index: integer(), end_index: integer(), step: non_neg_integer()]}

Specs

subpath_expression() :: {:subpath_expression, keyword()}

Specs

t() :: %Warpath.Expression{tokens: [token(), ...]}

Specs

token() ::
  root()
  | indexes()
  | slice()
  | dot_access()
  | filter()
  | scan()
  | union_property()
  | wildcard()

Specs

union_property() :: {:union, [dot_access(), ...]}

Specs

wildcard() :: {:wildcard, :*}

Link to this section Functions

Specs

compile(String.t()) :: {:ok, t()} | {:error, Warpath.ExpressionError.t()}

Compile a jsonpath string query

Example

iex> Warpath.Expression.compile("$.post.author")
{:ok, %Warpath.Expression{tokens: [ {:root, "$"}, {:dot, {:property, "post"}}, {:dot, {:property, "author"}} ]}}
Link to this macro

sigil_q(selector, modifiers)

View Source (macro)

Compiles jsonpath string query to expression.

Examples

iex> import Warpath.Expression
iex> ~q"$.post.author"
%Warpath.Expression{tokens: [ {:root, "$"}, {:dot, {:property, "post"}}, {:dot, {:property, "author"}} ]}