Jaxon v0.1.1 Jaxon.Path View Source

Utility module for parsing and encoding JSON path expressions.

Link to this section Summary

Functions

Encoding path expressions

Parse path expressions

Parse path expressions

Link to this section Types

Link to this type json_path() View Source
json_path() :: [String.t() | atom() | integer()]

Link to this section Functions

Link to this function encode(path) View Source
encode(json_path()) :: {:ok, String.t()} | {:error, String.t()}

Encoding path expressions:

iex> Jaxon.Path.encode([:root, "test", 0])
{:ok, "$.test[0]"}

How to handle encode errors:

iex> Jaxon.Path.encode([:root, :whoops, "test", 0])
{:error, "`:whoops` is not a valid JSON path segment"}
Link to this function parse(bin) View Source
parse(String.t()) :: {:ok, json_path()} | {:error, String.t()}

Parse path expressions:

iex> Jaxon.Path.parse("$[*].pets[0]")
{:ok, [:root, :all, "pets", 0]}

How to handle parse errors;

iex> Jaxon.Path.parse("$.test[x]")
{:error, "Expected an integer at `x]`"}
iex> Jaxon.Path.parse("$.\"test[x]")
{:error, "Ending quote not found for string at `\"test[x]`"}

Parse path expressions:

iex> Jaxon.Path.parse!("$[*].pets[0]")
[:root, :all, "pets", 0]