ComfyUI Extension: Simple JSON Parser Node for ComfyUI
A custom node for ComfyUI to parse and extract data from JSON strings.
Custom Nodes (10)
README
JSON Management Nodes for ComfyUI
A collection of custom nodes for ComfyUI to manipulate and process JSON data.
为ComfyUI提供的一套JSON数据处理节点集合。
Features
- Parse and extract JSON data
- Random value selection
- JSON object and array iteration
- JSON merging and modification
- JSON generation and formatting
- Key checking and length calculation
Installation
- Go to your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes/ - Clone the repository:
git clone [email protected]:Q-Bug4/Comfyui-Json-Nodes.git - Restart ComfyUI or reload custom nodes.
Available Nodes
1. Simple JSON Parser
- Inputs:
json_string: JSON stringpath: Data path (optional)
- Outputs:
parsed_data: Parsed JSON or specific valuearray_size: Size if result is array
2. Random JSON Value
- Inputs:
json_input: JSON stringmax_depth: Maximum depth for random selection
- Outputs:
random_value: Randomly selected value
3. JSON Object Iterator
- Inputs:
json_input: JSON objectindex: Current indexmode: Iteration mode (fixed/incr/decr)
- Outputs:
key: Current keyvalue: Current valuecurrent_index: Current positiontotal_items: Total number of items
4. JSON Array Iterator
- Inputs:
json_input: JSON arrayindex: Current indexmode: Iteration mode (fixed/incr/decr)
- Outputs:
item: Current itemcurrent_index: Current positiontotal_items: Total number of items
5. JSON Merge
- Inputs:
json_input_1: First JSONjson_input_2: Second JSONmerge_strategy: Override/Preserve/Concat
- Outputs:
merged_json: Combined JSON result
6. JSON Modifier
- Inputs:
json_input: JSON to modifypath: Path to modifynew_value: New value
- Outputs:
modified_json: Updated JSON
7. JSON Generator
- Inputs:
key_value_pairs: Key-value pairsis_array: Generate array instead of object
- Outputs:
generated_json: New JSON structure
8. JSON Length
- Inputs:
json_input: JSON input
- Outputs:
length: Number of items
9. JSON Key Checker
- Inputs:
json_input: JSON objectkey: Key to check
- Outputs:
exists: Boolean resultvalue: Value if exists
10. JSON Stringifier
- Inputs:
json_input: JSON inputindent: Indentation spacessort_keys: Sort keys alphabetically
- Outputs:
json_string: Formatted JSON string
Path Syntax
- Nested objects:
object.nestedObject.property - Array elements:
array[0]orarray.0 - Complex structures:
object.array[2].property
Examples
1. Iterating Through JSON
# Input JSON
{
"users": [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]
}
# Using Array Iterator with mode="incr"
# Will output each user object in sequence
2. Merging JSON Objects
# First input
{"name": "John", "age": 30}
# Second input
{"age": 31, "city": "New York"}
# Result with strategy="override"
{"name": "John", "age": 31, "city": "New York"}
3. Random Value Selection
# Input JSON
{
"colors": ["red", "blue", "green"],
"sizes": {"S": 10, "M": 20, "L": 30}
}
# Random value might return any color or size value
Error Handling
ValueError is raised for:
- Invalid JSON strings
- Invalid paths or keys
- Type mismatches
- Array index out of bounds
Contributing
Improvements are welcome! Steps:
- Fork the repository
- Create a new branch
- Make changes
- Push to your fork
- Submit a Pull Request
License
MIT License. See LICENSE file for details.