View Source JSONPathEx.Parser (JSONPathEx v0.1.0)
Defines parsers for JSONPath expressions using NimbleParsec.
This module handles the parsing of JSONPath syntax, including filters, grouping, and the main JSONPath expression. The parsed output is structured and tagged for further processing.
Summary
Functions
Parses an expression with logical and arithmetic operators.
Parses a filter expression (e.g., [?(@.price < 10)]).
Parses a grouping expression, optionally negated.
Parses a JSONPath expression.
Parses a JSONPath string and returns the parsed result or an error.
Functions
@spec expression(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parses an expression with logical and arithmetic operators.
Expressions are composed of terms combined with operators.
@spec filter_expression(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parses a filter expression (e.g., [?(@.price < 10)]).
Filters use expressions and logical operators for conditional selection.
@spec grouping(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parses a grouping expression, optionally negated.
Grouping expressions allow logical combinations of conditions.
@spec jsonpath(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parses a JSONPath expression.
Returns a tagged structure on success or an error tuple on failure.
Parses a JSONPath string and returns the parsed result or an error.
Examples
iex> JSONPathEx.Parser.parse("$.store.book[*].author")
{:ok, [{:root, "$"}, {:dot_child, "store"}, ...]}
iex> JSONPathEx.Parser.parse("invalid")
{:error, "Invalid JSONPath expression"}