# `JSONPath`
[🔗](https://github.com/IgnacioGoldchluk/json_path/blob/main/lib/json_path.ex#L1)

[RFC-9535](https://www.rfc-editor.org/rfc/rfc9535) compliant JSON Path evaluator.

# `json`

```elixir
@type json() ::
  nil
  | number()
  | String.t()
  | boolean()
  | [json()]
  | %{required(String.t()) =&gt; json()}
```

# `build`

```elixir
@spec build(String.t()) :: {:ok, JSONPath.AST.t()} | {:error, JSONPath.Error.t()}
```

Builds a JSON Path query `t:JSONPath.AST.t/0`. Returns `{:ok, ast}` or
`{:error, JSONPath.Error.t()}`.

Prefer this function when running the same query multiple times, since building the query
each time performs potentially expensive semantic checks.

# `evaluate`

```elixir
@spec evaluate(json(), String.t() | JSONPath.AST.t()) ::
  {:ok, [json()]} | {:error, JSONPath.Error.t()}
```

Evaluates a JSON value against the given query string or parsed AST. Returns an
`{:ok, results}` or `{:error, JSONPath.Error.t()}` tuple

## Examples

    iex> JSONPath.evaluate(["aba", "bbab", "bab"], "$[?match(@, 'b.b')]")
    {:ok, ["bab"]}

    iex> JSONPath.evaluate(%{"foo" => [1, 2, 3, 4]}, "$.foo[::-1]")
    {:ok, [4, 3, 2, 1]}

    iex> JSONPath.evaluate(%{"foo" => %{"bar" => "baz"}}, "$[?length(@)]")
    {:error, %JSONPath.Error{
      type: :invalid_expression,
      expression: "length(@)",
      message: "comparison operator expected"
      }
    }

---

*Consult [api-reference.md](api-reference.md) for complete listing*
