class

Json::Tools::Pointer

Inherits Reference / Object

An implementatition of https://tools.ietf.org/html/rfc6901

This class represent a JSON pointer that can be evaluated on a JSON object:

json_obj = JSON.parse(some_json_object_string)
pointer = Json::Tools::Pointer.new("/foo/0/bar")
value = pointer.eval(json_obj)

Constructors

new(path : String)
Source

Instance methods

eval(document : JSON::Any) : JSON::Any

Evaluates the pointer on the given JSON object.

json_obj = JSON.parse(<<-JSON
  {
    "foo": [
      {
        "bar": 12,
        "baz": 34
      },
      {
        "bar": 56,
        "baz": 78
      }
    ],
    "baz": "plaz"
  }
  JSON
)
pointer = Json::Tools::Pointer.new("/foo/1/bar")
value = pointer.eval(json_obj) # => 56
Source
key

Returns the element name at which this pointer points to.

pointer = Json::Tools::Pointer.new("/foo/0/bar")
key = pointer.key # => bar
Source
parent

Returns a pointer to the parent element in the JSON object.

pointer = Json::Tools::Pointer.new("/foo/0/bar")
parent = pointer.parent # => /foo/0
Source
path
Source