Comfyui-Simple-Json-Node

Comfyui-Simple-Json-Node
★ 9

JSON处理数据提取合并与修改ComfyUI节点
解析与提取JSON字符串,支持随机值选择、遍历、合并修改与生成格式化,便于在ComfyUI流程中动态管理数据。
💡 在ComfyUI节点流程中解析、提取并修改JSON数据。
🍴 3 Forks💻 Python🔄 2025-03-27
📦
网盘下载
复制链接后前往夸克网盘下载
https://pan.quark.cn/s/af9fbf81e746
📄 README

JSON Management Nodes for ComfyUI

A collection of custom nodes for ComfyUI to manipulate and process JSON data.

为ComfyUI提供的一套JSON数据处理节点集合。

中文版 README

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 git@github.com:Q-Bug4/Comfyui-Json-Nodes.git

    “`

  • Restart ComfyUI or reload custom nodes.
  • Available Nodes

    1. Simple JSON Parser

  • Inputs:
  • json_string: JSON string
  • path: Data path (optional)
  • Outputs:
  • parsed_data: Parsed JSON or specific value
  • array_size: Size if result is array
  • 2. Random JSON Value

  • Inputs:
  • json_input: JSON string
  • max_depth: Maximum depth for random selection
  • Outputs:
  • random_value: Randomly selected value
  • 3. JSON Object Iterator

  • Inputs:
  • json_input: JSON object
  • index: Current index
  • mode: Iteration mode (fixed/incr/decr)
  • Outputs:
  • key: Current key
  • value: Current value
  • current_index: Current position
  • total_items: Total number of items
  • 4. JSON Array Iterator

  • Inputs:
  • json_input: JSON array
  • index: Current index
  • mode: Iteration mode (fixed/incr/decr)
  • Outputs:
  • item: Current item
  • current_index: Current position
  • total_items: Total number of items
  • 5. JSON Merge

  • Inputs:
  • json_input_1: First JSON
  • json_input_2: Second JSON
  • merge_strategy: Override/Preserve/Concat
  • Outputs:
  • merged_json: Combined JSON result
  • 6. JSON Modifier

  • Inputs:
  • json_input: JSON to modify
  • path: Path to modify
  • new_value: New value
  • Outputs:
  • modified_json: Updated JSON
  • 7. JSON Generator

  • Inputs:
  • key_value_pairs: Key-value pairs
  • is_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 object
  • key: Key to check
  • Outputs:
  • exists: Boolean result
  • value: Value if exists
  • 10. JSON Stringifier

  • Inputs:
  • json_input: JSON input
  • indent: Indentation spaces
  • sort_keys: Sort keys alphabetically
  • Outputs:
  • json_string: Formatted JSON string
  • Path Syntax

  • Nested objects: object.nestedObject.property
  • Array elements: array[0] or array.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.