Module: KazeClient::JsonUtils

Defined in:
lib/kaze_client/json_utils.rb

Overview

Utility methods to interact with JSON data

See Also:

Author:

Since:

  • 0.2.1

Class Method Summary collapse

Class Method Details

.fetch_node(json, path) ⇒ Object?

Fetch a node in given JSON

Parameters:

Returns:

  • (Object, nil)

    The node or data corresponding to the path or nil

Since:

  • 0.2.1



34
35
36
# File 'lib/kaze_client/json_utils.rb', line 34

def self.fetch_node(json, path)
  fetch_nodes(json, path).first
end

.fetch_nodes(json, path) ⇒ Array

Fetch nodes in given JSON

Parameters:

Returns:

  • (Array)

    The nodes or data corresponding to the path

Since:

  • 0.2.1



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kaze_client/json_utils.rb', line 16

def self.fetch_nodes(json, path)
  json = case json
         when ::KazeClient::Response
           json.parsed_response
         when String
           JSON.parse(json)
         else
           json
         end

  JsonPath.on(json, path)
end