Method: JsonDiff.json_pointer

Defined in:
lib/json-diff/operation.rb

.json_pointer(path) ⇒ Object

Convert a list of strings or numbers to an RFC6901 JSON pointer. tools.ietf.org/html/rfc6901



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/json-diff/operation.rb', line 5

def self.json_pointer(path)
  return "" if path == []

  escaped_path = path.map do |key|
    if key.is_a?(String)
      key.gsub('~', '~0')
         .gsub('/', '~1')
    else
      key.to_s
    end
  end.join('/')

  "/#{escaped_path}"
end