class Json::Tools::Pointer

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(path : String) #

[View source]

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

[View source]
def key #

Returns the element name at which this pointer points to.

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

[View source]
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

[View source]
def path : String #

[View source]