View Source JsonPointer (json_ptr v0.3.0)
Implementation of JSONPointer.
A JSONpointer URI is converted into an internal term representation and this representation
may be used with resolve!/2
to parse a decoded JSON term.
See: https://www.rfc-editor.org/rfc/rfc6901 for the specification.
Note: Do not rely on the private internal implementation of JSON, it may change in the future.
Link to this section Summary
Functions
iex> {:ok, ptr} = "/foo/bar" |> JsonPointer.from_uri |> JsonPointer.backtrack iex> JsonPointer.to_uri(ptr) "/foo"
like backtrack/1
, but raises if attempted to backtrack from the root.
converts a uri to a JSONJsonPointer
resolves a JSONPointer given a pointer and some json data
resolves a JSONPointer given a pointer and some json data
creates a JSONPointer to its URI equivalent.
appends information to the JsonPointer structure. Can take either a url path-alike or a list of traversals.
Link to this section Types
@opaque t()
Link to this section Functions
iex> {:ok, ptr} = "/foo/bar" |> JsonPointer.from_uri |> JsonPointer.backtrack iex> JsonPointer.to_uri(ptr) "/foo"
like backtrack/1
, but raises if attempted to backtrack from the root.
converts a uri to a JSONJsonPointer
iex> JsonPointer.from_uri("/") # the root-only case
[]
iex> JsonPointer.from_uri("/foo/bar")
["foo", "bar"]
iex> JsonPointer.from_uri("/foo~0bar/baz")
["foo~bar", "baz"]
iex> JsonPointer.from_uri("/currency/%E2%82%AC")
["currency", "€"]
resolves a JSONPointer given a pointer and some json data
iex> JsonPointer.resolve(true, "/")
{:ok, true}
iex> JsonPointer.resolve(%{"foo~bar" => "baz"}, "/foo~0bar")
{:ok, "baz"}
iex> JsonPointer.resolve(%{"€" => ["quux", "ren"]}, JsonPointer.from_uri("/%E2%82%AC/1"))
{:ok, "ren"}
resolves a JSONPointer given a pointer and some json data
iex> JsonPointer.resolve!(true, "/")
true
iex> JsonPointer.resolve!(%{"foo~bar" => "baz"}, "/foo~0bar")
"baz"
iex> JsonPointer.resolve!(%{"€" => ["quux", "ren"]}, JsonPointer.from_uri("/%E2%82%AC/1"))
"ren"
creates a JSONPointer to its URI equivalent.
options
:authority
prepends a context to the uri.
iex> JsonPointer.to_uri(["foo", "bar"])
"/foo/bar"
iex> JsonPointer.to_uri(["foo~bar", "baz"])
"/foo~0bar/baz"
iex> JsonPointer.to_uri(["currency","€"])
"/currency/%E2%82%AC"
iex> JsonPointer.to_uri([], authority: "foo")
"foo#/"
appends information to the JsonPointer structure. Can take either a url path-alike or a list of traversals.
iex> ptr = JsonPointer.from_uri("/foo/bar")
iex> ptr |> JsonPointer.traverse("baz") |> JsonPointer.to_uri
"/foo/bar/baz"
iex> ptr |> JsonPointer.traverse("baz/quux") |> JsonPointer.to_uri
"/foo/bar/baz/quux"
iex> ptr |> JsonPointer.traverse(["baz", "quux"]) |> JsonPointer.to_uri
"/foo/bar/baz/quux"