JSON Pointer v1.3.3 JSONPointer View Source

Link to this section Summary

Functions

Ensures that the given list has size number of elements

Escapes a reference token

Extracts a list of JSON pointer paths from the given object

Retrieves the value indicated by the pointer from the object

Retrieves the value indicated by the pointer from the object

Tests if an object has a value for a JSON pointer

Merges the incoming dst object into src

Converts a JSON pointer into a list of reference tokens

Removes an attribute of object referenced by pointer

Sets a new value on object at the location described by pointer

Unescapes a reference token

Link to this section Types

Link to this type container() View Source
container() :: map() | list()
Link to this type existing() View Source
existing() :: t()
Link to this type input() View Source
input() :: map()
Link to this type pointer() View Source
pointer() :: String.t() | [String.t()]
Link to this type pointer_list() View Source
pointer_list() :: [String.t()]
Link to this type removed() View Source
removed() :: t()
Link to this type t() View Source
t() ::
  nil |
  true |
  false |
  list() |
  float() |
  integer() |
  String.t() |
  map()

Link to this section Functions

Link to this function ensure_list_size(list, size) View Source
ensure_list_size(list(), non_neg_integer()) :: list()

Ensures that the given list has size number of elements

## Examples

iex> JSONPointer.ensure_list_size( [], 2 )
[nil, nil]

Escapes a reference token

## Examples

iex> JSONPointer.escape "hello~bla"
"hello~0bla"
iex> JSONPointer.escape "hello/bla"
"hello~1bla"
Link to this function extract(object) View Source
extract(input()) :: {:ok, pointer_list()}

Extracts a list of JSON pointer paths from the given object

## Examples iex> JSONPointer.extract( %{“a”=>%{“b”=>[“c”,”d”]}} ) {:ok, [{“/a/b/0”, “c”}, {“/a/b/1”, “d”}] }

iex> JSONPointer.extract( %{“a”=>[10, %{“b”=>12.5}], “c”=>99} ) {:ok, [{“/a/0”, 10}, {“/a/1/b”, 12.5}, {“/c”, 99}] }

Link to this function get(obj, pointer) View Source
get(input(), pointer()) :: {:ok, t()} | {:error, msg()}

Retrieves the value indicated by the pointer from the object

## Examples

iex> JSONPointer.get( %{ "fridge" => %{ "door" => "milk" } }, "/fridge/door" )
{:ok, "milk"}

iex> JSONPointer.get( %{ "contents" => [ "milk", "butter", "eggs" ]}, "/contents/2" )
{:ok, "eggs"} 

iex> JSONPointer.get( %{ "milk" => true, "butter" => false}, "/cornflakes" )
{:error, "token not found: cornflakes"}

iex> JSONPointer.get( %{ "contents" => [ "milk", "butter", "eggs" ]}, "/contents/4" )
{:error, "list index out of bounds: 4"} 
Link to this function get!(obj, pointer) View Source
get!(input(), pointer()) :: {:ok, t()} | no_return()

Retrieves the value indicated by the pointer from the object

raises an exception if there is an error

## Examples

iex> JSONPointer.get!( %{}, "/fridge/milk" )
** (ArgumentError) json pointer key not found: fridge
Link to this function has(obj, pointer) View Source
has(input(), pointer()) :: boolean()

Tests if an object has a value for a JSON pointer

## Examples

iex> JSONPointer.has( %{ "milk" => true, "butter" => false}, "/butter" )
true

iex> JSONPointer.has( %{ "milk" => true, "butter" => false}, "/cornflakes" )
false
Link to this macro is_get_list(operation, list, tokens) View Source (macro)
Link to this macro is_get_map(operation, map, tokens) View Source (macro)
Link to this macro is_remove_from_list(operation, list, tokens) View Source (macro)
Link to this macro is_remove_from_map(operation, map, tokens) View Source (macro)
Link to this macro is_set_list(operation, list, tokens) View Source (macro)
Link to this macro is_set_list_nil_child(operation, parent, tokens, child) View Source (macro)
Link to this macro is_set_list_no_tokens(operation, list) View Source (macro)
Link to this macro is_set_map(operation, map, tokens) View Source (macro)
Link to this macro is_set_map_no_tokens(operation, map) View Source (macro)
Link to this macro is_set_nil_container(operation, container) View Source (macro)
Link to this macro is_set_remove_list(operation, list) View Source (macro)
Link to this macro is_set_remove_map(operation, map) View Source (macro)
Link to this function merge(src, dst) View Source
merge(container(), container()) :: {:ok, container()}

Merges the incoming dst object into src

## Examples

iex> JSONPointer.merge( %{“a”=>1}, %{“b”=>2} ) {:ok, %{“a”=>1,”b”=>2} }

iex> JSONPointer.merge( [“foo”, “bar”], [“baz”] )

Link to this function parse(pointer) View Source
parse(pointer()) :: {:ok, [String.t()]} | {:error, msg(), pointer()}

Converts a JSON pointer into a list of reference tokens

## Examples

iex> JSONPointer.parse("/fridge/butter")
{:ok, [ "fridge", "butter"] }
Link to this function remove(object, pointer) View Source
remove(input(), pointer()) :: {:ok, t(), removed()} | {:error, msg()}

Removes an attribute of object referenced by pointer

## Examples

iex> JSONPointer.remove( %{"fridge" => %{ "milk" => true, "butter" => true}}, "/fridge/butter" )
{:ok, %{"fridge" => %{"milk"=>true}}, true }

iex> JSONPointer.remove( %{"fridge" => %{ "milk" => true, "butter" => true}}, "/fridge/sandwich" )
{:error, "json pointer key not found: sandwich", %{ "butter" => true, "milk" => true}}
Link to this function set(object, pointer, value) View Source
set(input(), pointer(), t()) ::
  {:ok, t(), existing()} |
  {:error, msg()}

Sets a new value on object at the location described by pointer

## Examples

iex> JSONPointer.set( %{}, "/example/msg", "hello")
{:ok, %{ "example" => %{ "msg" => "hello" }}, nil }

iex> JSONPointer.set( %{}, "/fridge/contents/1", "milk" )
{:ok, %{"fridge" => %{"contents" => [nil, "milk"]}}, nil }

iex> JSONPointer.set( %{"milk"=>"full"}, "/milk", "empty")
{:ok, %{"milk" => "empty"}, "full"}

Unescapes a reference token

## Examples

iex> JSONPointer.unescape "hello~0bla"
"hello~bla"
iex> JSONPointer.unescape "hello~1bla"
"hello/bla"