class Json::Tools::Pointer
- Json::Tools::Pointer
- Reference
- Object
Overview
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 ...
pointer = Json::Tools::Pointer.new("/foo/0/bar")
value = pointer.eval(json_obj)
Defined in:
json-tools/pointer.crConstructors
Instance Method Summary
-
#eval(document : JSON::Any) : JSON::Any
Evaluates the pointer on the given JSON object.
-
#key
Returns the element name at which this pointer points to.
-
#parent
Returns a pointer to the parent element in the JSON object.
- #path : String
Constructor Detail
Instance Method Detail
def 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
def key
#
Returns the element name at which this pointer points to.
pointer = Json::Tools::Pointer.new("/foo/0/bar")
key = pointer.key # => bar
def 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