Path
The Path node in Magick allows you to search for and extract values from a nested object using a dot-notation path string. It’s a powerful utility for working with complex data structures in your spells.Inputs
pathToSearch(string, required): The path to search for in the object, using dot-notation (e.g., “user.address.city”).obj(object, required): The object to search.
Outputs
result(object): The value found at the specified path in the object. If the path is not found, the output will be undefined.
Configuration
This node has no additional configuration options.Usage
- Connect an object to the
objinput. This is the object you want to search. - Specify the path you want to search for in the
pathToSearchinput, using dot-notation. For example, if you want to find the city in{ user: { address: { city: "New York" } } }, you would use the path “user.address.city”. - The value found at the specified path will be output from the
resultoutput. If the path is not found, the output will be undefined.
Example
Let’s say you have a spell that fetches user data from an API, and you want to extract the user’s city. You could use the Path node like this:- Use an HTTP Request node to fetch the user data and connect its output to the
objinput of the Path node. - Set the
pathToSearchinput to “user.address.city”. - Connect the
resultoutput to a Text node to display the city.
Best Practices
- Always double-check your path string to ensure it matches the structure of your object exactly.
- If you’re not sure about the structure of your object, use a Debug node to log it to the console so you can inspect it.
- Remember that the path is case-sensitive.
Common Issues
- If the path is not found in the object, the
resultoutput will be undefined. Make sure to handle this case in your spell if necessary. - Be careful not to confuse the dot-notation used in the
pathToSearchinput with the Magick templating syntax, which also uses double curly braces{{ }}.
