This is an implementation of JSON Pointer (RFC 6901) for Elixir.
Add a dependency to your project mix.exs:
def deps do
[{:odgn_json_pointer, "~> 2.2"}]
endThen update your dependencies:
$ mix deps.getRetrieves the value indicated by the pointer from the object
JSONPointer.get( %{ "fridge" => %{ "door" => "milk" } }, "/fridge/door" )
# => {:ok, "milk"}Retrieves the value indicated by the pointer from the object, and throws an exception if not found
JSONPointer.get!( %{}, "/fridge/milk" )
** (ArgumentError) json pointer key not found: fridgeSets the value indicated by the pointer in the object
JSONPointer.set( %{}, "/example/msg", "hello")
# => {:ok, %{ "example" => %{ "msg" => "hello" }}, nil }Sets the value indicated by the pointer in the object
JSONPointer.set!( %{}, "/example/msg", "hello")
# => %{ "example" => %{ "msg" => "hello" }}Returns an array of JSON pointer paths mapped to their values
JSONPointer.dehydrate( %{"a"=>%{"b"=>["c","d"]}} )
# => {:ok, [{"/a/b/0", "c"}, {"/a/b/1", "d"}] }Returns an array of JSON pointer paths mapped to their values
JSONPointer.dehydrate!!( %{"a"=>%{"b"=>["c","d"]}} )
# => [{"/a/b/0", "c"}, {"/a/b/1", "d"}]Merges the dst container into src
JSONPointer.merge( %{"a"=>1}, %{"b"=>2} )
# => {:ok, %{"a"=>1,"b"=>2} }Merges the dst container into src
JSONPointer.merge!( %{"a"=>1}, %{"b"=>2} )
# => %{"a"=>1,"b"=>2}Returns true if the given value exists in the object indicated by the pointer
JSONPointer.has( %{ "milk" => true, "butter" => false}, "/butter" )
# => trueRemoves the value from the object indicated by the pointer
JSONPointer.remove( %{"fridge" => %{ "milk" => true, "butter" => true}}, "/fridge/butter" )
# => {:ok, %{"fridge" => %{"milk"=>true}}, true }inspiration from https://github.com/manuelstofer/json-pointer
made without peeking (much) at the source of https://github.com/xavier/json_pointer
Made in Exeter, UK.
This software is licensed under the MIT license.