Skip to content
Implementation of RFC 6901 which defines a string syntax for identifying a specific value within a JSON document
Elixir
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
config
lib
test
.gitignore
LICENSE
README.md
mix.exs
mix.lock

README.md

JSON Pointer

An implementation of RFC 6901 which defines a string syntax for identifying a specific value within a JSON document.

Installation

Add a dependency to your project mix.exs:

def deps do
  [{:json_pointer, "~> 0.0.1"}]
end

Usage

document = %{
  "key" => "value",
  "list" => [1, 2, 3],
  "deeply" => %{
    "nested" =>
      %{"values" => [
        %{"x" => 1},
        %{"x" => 2}
      ]
    }
  }
}

JSONPointer.resolve(document, "/key")
# => {:ok, "value"}
JSONPointer.resolve(document, "/list/1")
# => {:ok, 2}
JSONPointer.resolve(document, "/deeply/nested/values/0")
# => {:ok, %{"x" => 1}}
JSONPointer.resolve(document, "/deeply/nested/values/1/x")
# => {:ok, 2}
JSONPointer.resolve(document, "/list/4")
# => {:error, "index 4 out of bounds in [1, 2, 3]"}

Dependencies

This library works with deserialized documents and does not include a JSON parser.

Something went wrong with that request. Please try again.