Node
The Node
class represents a specific location in JSON data and allows navigation relative to that location. It provides a way to traverse and explore component data with lazy evaluation, meaning data is only accessed when explicitly requested through methods like get_value()
, exists()
, or iteration.
Data Access Methods
get_value
get_value(path=".")
Gets the raw value at the given path relative to this node.
path (str): JSON path relative to this node (default: "." for this node's value)
Returns: The raw value (dict, list, string, number, boolean, etc.)
Raises:
ValueError
if the path is invalid or doesn't exist,NoDataError
if data is not available yet
Example:
# Get the current node's value
node = check.get_node(".config.database")
host = node.get_value(".host") # Relative to .config.database
port = node.get_value(".port") # Relative to .config.database
# Get the node's own value
database_config = node.get_value() # Returns the entire database config object as a dict
get_node
get_node(path)
Gets a Node at the given path relative to this node. Uses lazy evaluation - data is not accessed until value is needed.
path (str): JSON path relative to this node
Returns: A new Node instance at the specified path
Raises:
ValueError
if the path syntax is invalid
exists
exists(path=".")
Checks if a path exists relative to this node.
path (str): JSON path relative to this node (default: "." to check if this node exists)
Returns:
True
if the path exists,False
otherwise
Example:
host_node = check.get_node(".config.host")
if host_node.exists():
host = host_node.get_value()
Iteration Methods
Iterating over Node
for item in node:
# Process item
Makes Node iterable. For dictionaries, yields keys. For arrays, yields Node objects.
For dict-like data: Yields string keys
For array-like data: Yields Node objects for each array element
Raises:
ValueError
if the node doesn't point to a dict or array,NoDataError
if data is not available yet
Example:
# Iterate over dictionary keys
config_node = check.get_node(".config")
for key in config_node:
print(f"Config key: {key}")
# Iterate over array elements
items_node = check.get_node(".items")
for item_node in items_node:
name = item_node.get_value(".name")
print(f"Item name: {name}")
items
items()
Get key-value pairs when this Node points to a dict-like structure.
Returns: Iterator of (key, Node) tuples for dict-like data
Raises:
ValueError
if the node doesn't point to a dictionary,NoDataError
if data is not available yet
Example:
config_node = check.get_node(".config")
for key, value_node in config_node.items():
value = value_node.get_value()
print(f"{key}: {value}")
Last updated