Extract Object Path Node
Overview
The Extract Object Path Node allows you to run jsonpath queries on an object. This is useful for extracting data from a JSON object or array. Some use-cases include:
- Extracting data from a JSON object returned by an API
- Extracting properties from the result of an Extract JSON node or Extract YAML node
- Accessing individual elements of an array
- Complex queries such as
$.store.book[?(@.price < 10)]
to perform filtering
Any valid jsonpath-plus
query can be used, but just be careful about complex queries.
The input to Extract Object path must be either an object, or an array of any data type. You can also query properties of non-object data types, such as strings, such as $.length
to get the length of a string.
- Inputs
- Outputs
- Editor Settings
Inputs
Title | Data Type | Description | Default Value | Notes |
---|---|---|---|---|
Object | object or any[] or string | The object to query using the path. | (required) |
Outputs
Title | Data Type | Description | Notes |
---|---|---|---|
Match | any | If the value is found in the object, the value matched. | If the value is not found, this port is not ran. |
All Matches | any[] | When using a path that can match multiple times, such as $.someArray[*] , represents all paths of the object that match. | If the value is not found, this port will run with an empty array. |
Editor Settings
Setting | Description | Default Value | Use Input Toggle | Input Data Type |
---|---|---|---|---|
Path | The jsonpath path to use to extract properties from the input object. | $ | Yes | string |
Example 1: Extract a property from an object
Create an Object Node and set the value to the following:
{
"name": "John Doe",
"age": 30
}Create an Extract Object Path Node and connect the Object Node to it. Set the
Path
of the Extract Object Path Node to:$.name
Run the graph. The Extract Object Path Node should output the value
John Doe
.
Example 2: Extract properties from an array of objects
Create an Object Node and set the value to the following:
[
{
"name": "John Doe",
"age": 30
},
{
"name": "Jane Doe",
"age": 25
}
]Create an Extract Object Path Node and connect the Object Node to it. Set the
Path
of the Extract Object Path Node to:$[*].name
Run the graph. The Extract Object Path Node's
all_matches
output should have the valueJohn Doe
andJane Doe
. Thematch
output contains the first match, which isJohn Doe
.
Example 3: Extract a dynamic property from an object
Create an Object Node and set the value to the following:
{
"name": "John Doe",
"age": 30
}Create a Text node and set the value to
age
.Create another Text node and set the value to
$.{{input}}
. Connect the first Text node to the second Text node.Create an Extract Object Path node and enable the input port for the
Path
setting. Connect the second Text node to the Extract Object Path node'sPath
input port. Connect the Object Node to the Extract Object Path node.Run the graph. Note that the path is constructed dynamicalled, and the
age
is extracted from the object.
Error Handling
If the path is invalid, the Extract Object Path Node will throw an error. If the path is valid, but the value is not found, the match
output will not run, and the all_matches
output will run with an empty array.
FAQs
Q: Does the Extract Object Path Node only work with objects?
A: No, it can also work with arrays and other JavaScript values that have properties, such as strings. For example, you can use $.length
to get the length of a string.
Q: Can I split the Extract Object Path Node in order to execute a command on an array of objects?
A: It is recommended to simply use the *
operator and the All Matches
output, but there can be cases where splitting the node is appropriate. For example with an array of objects that themselves contain arrays, and you want to extract all sub-arrays, you can either to $[*].someArray
or split the node and use $.someArray
on the split node.
Q: Can I use the Extract Object Path Node to extract data from a JSON object returned by an API?
A: Yes, you can use the HTTP Call Node to make an API request, and then use the Extract Object Path Node to extract data from the response.