Defines parsers for JSONPath expressions using NimbleParsec.
Handles 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: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses an expression with logical and arithmetic 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: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses a filter expression (e.g., [?(@.price < 10)]).
Supports both [?(expr)] and shorthand [?expr].
@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: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses a grouping expression, optionally negated.
@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: non_neg_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> {:ok, ast} = JSONPathEx.Parser.parse("$.store.book[*].author")
iex> List.first(ast)
{:root, "$"}
iex> {:error, msg} = JSONPathEx.Parser.parse("invalid")
iex> String.contains?(msg, "expected")
true