JSON Parameter Extraction Node
The JSON Parameter Extraction Node is a component in FlowAI used for processing JSON data. It can extract specific data from JSON strings output by the previous node and pass it as variables to subsequent nodes. By properly using the JSON Parameter Extraction Node, you can easily handle complex JSON data structures.
Node Configuration
Basic Settings
-
Node Name
- Set a descriptive name for the JSON Parameter Extraction Node
- Recommend using names that reflect the extraction purpose, such as “Extract User Info”, “Get Order Details”, etc.
- Naming convention: Use verb + noun form, like “Extract User ID”, “Get Order Status”
-
JSON Data Source
- Select or input the output variable from the previous node, such as
$LLM1.result
- Ensure the data source is a valid JSON string
- Select or input the output variable from the previous node, such as
-
JSON Path
- Input the JSON path to extract, such as
output.data
,output.list.1
, etc. - Path format: Use dot notation
.
for hierarchy, use numbers for array indices (starting from 0)
- Input the JSON path to extract, such as
Output
- Output variable format is
$NodeName.output
, for example$JSONExtract1.output
Usage Examples
1. Extracting Simple JSON Data
Let’s extract data from a simple JSON string:
-
A simple JSON string
{"output": "Hello, World!"} -
JSON Parameter Extraction Configuration
Node Name: JSONParamExtraction1JSON Data Source: $input.dataJSON Path: output -
Output
Use the extracted data for subsequent processing
2. Extracting Nested JSON Data
Handling nested JSON data structures:
-
A nested JSON string
{"output": {"advanceList": [{ "data": "Hello, World!" }]}} -
JSON Parameter Extraction Configuration
Node Name: ExtractNestedDataJSON Data Source: $input.dataJSON Path: output.advanceList.0.data -
Output
3. Extracting Elements from Arrays
Demonstrating how to extract specific elements from JSON arrays:
-
A JSON array
{"output": {"list": ["Hello", "World", "FlowAI"]}} -
JSON Parameter Extraction Configuration
Node Name: ExtractArrayElementJSON Data Source: $input.dataJSON Path: output.list.1 -
Output
Advanced Usage
1. Multi-level Extraction
You can achieve multi-level data extraction by connecting multiple JSON Parameter Extraction Nodes, suitable for complex JSON data structures:
[Level 1 Extraction] --> [Level 2 Extraction] --> [Level 3 Extraction]
Syntax Guidelines
The JSON Parameter Extraction Node uses GJSON path syntax, supporting rich query and operation features. Here’s the complete syntax explanation:
Basic Paths
- Use dot notation
.
for hierarchy - Array indices start from 0
{ "user": { "tags": ["AI", "Developer", "GPT"] }}
user.tags.1 // Extracts "Developer"
Wildcards
*
matches any length of characters?
matches a single character
user.t* // Matches tags arrayuser.ta?s // Matches tags array
Escape Characters
Use \
to escape special characters:
{ "file.name": "config.json"}
file\.name // Extracts "config.json"
Array Operations
#
gets array length#(query condition)
array query
{ "users": [ { "name": "Alice", "age": 25 }, { "name": "Bob", "age": 30 } ]}
users.# // Returns 2 (array length)users.#.name // Returns ["Alice","Bob"]users.#(age>25).name // Returns "Bob"
Query Syntax
Supports various query operators:
{ "products": [ { "id": 1, "price": 99, "tags": ["electronics", "sale"] }, { "id": 2, "price": 199, "tags": ["furniture"] } ]}
// Comparison queriesproducts.#(price>=100).id // Returns 2// Pattern matchingproducts.#(tags%"*sale*").id // Returns 1// Nested queriesproducts.#(tags.#(=="furniture"))#.id // Returns 2
Modifiers
Use data processing modifiers with the @
symbol:
products.@reverse // Reverse array orderproducts.@pretty // Beautify JSON outputproducts.@ugly // Compress JSON formatproducts.@join // Merge multiple objects
Common Issues
Debugging Tips
Using Output Nodes Add output nodes to each branch to help debug the flow:
[JSON Parameter Extraction] --> [Output Node(print extraction result)]
By properly using the JSON Parameter Extraction Node, you can easily handle complex JSON data structures. Remember to carefully plan extraction paths and ensure path accuracy and validity to guarantee reliable workflow operation.