View Source Warpath.Expression (Warpath v0.6.3)

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

@type dot_access() :: {:dot, property()}
@type filter() ::
  {:filter,
   has_children() | {operator() | guard(), subpath_expression() | term()}}
@type guard() ::
  :is_atom
  | :is_binary
  | :is_boolean
  | :is_float
  | :is_integer
  | :is_list
  | :is_map
  | :is_nil
  | :is_number
  | :is_tuple
@type has_children() :: {:has_children?, subpath_expression()}
@type indexes() :: {:indexes, [{:index_access, integer()}, ...]}
@type operator() ::
  :< | :> | :<= | :>= | :== | :!= | :=== | :!== | :not | :and | :or | :in
@type property() :: {:property, String.t() | atom()}
@type root() :: {:root, String.t()}
@type scan() :: {:scan, property() | wildcard() | filter() | indexes()}
@type slice() ::
  {:slice,
   start_index: integer(), end_index: integer(), step: non_neg_integer()}
@type subpath_expression() :: {:subpath_expression, keyword()}
@type t() :: %Warpath.Expression{tokens: [token(), ...]}
@type token() ::
  root()
  | indexes()
  | slice()
  | dot_access()
  | filter()
  | scan()
  | union_property()
  | wildcard()
@type union_property() :: {:union, [dot_access(), ...]}
@type wildcard() :: {:wildcard, :*}

Link to this section Functions

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

Compile a jsonpath string query

example

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

Examples

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