Nodes
Path#
The Path node in Magick allows you to extract a value from a nested object or array using a dot-notation path string. It's useful when you need to retrieve a specific piece of data from a complex data structure.
Inputs#
-
pathToSearch
(string, required): The dot-notation path string that specifies the location of the value you want to extract from the input object. For example,"user.address.city"
would retrieve thecity
value from theaddress
object nested within theuser
object. -
obj
(object, required): The input object or array from which you want to extract a value using the specified path.
Outputs#
result
(string): The value extracted from the input object at the specified path location. If the path is not found in the object, the output will be an empty string.
Configuration#
This node does not have any additional configuration options.
Usage#
-
Connect the object or array you want to search to the
obj
input of the Path node. -
Enter the dot-notation path string that leads to the value you want to extract in the
pathToSearch
input. For example, if you want to get the city from an address object nested within a user object, you would enter"user.address.city"
. -
The extracted value will be available at the
result
output of the Path node. You can then use this output as an input for other nodes in your spell.
Example#
Suppose you have a JSON object representing a user with the following structure:
To extract the city from this user object, you would:
- Connect the user JSON object to the
obj
input of the Path node. - Set the
pathToSearch
input to"address.city"
. - The
result
output of the Path node will contain the string"Anytown"
, which you can use in other parts of your spell.
Best Practices#
- Make sure to use the correct dot-notation syntax for the path string. Nested objects are separated by dots (
.
), and array indices are specified using square brackets ([]
). - If the specified path does not exist in the input object, the Path node will output an empty string. Handle this case appropriately in your spell logic.
Common Issues#
- Incorrect path string syntax: Ensure that your path string follows the correct dot-notation format, with objects separated by dots and array indices in square brackets.
- Trying to access a non-existent path: If the specified path does not exist in the input object, the Path node will output an empty string. Check your path string and input object structure if you're not getting the expected result.