- Added new nodes for JSON manipulation: RandomJSONValueNode, JSONObjectIteratorNode, JSONArrayIteratorNode, JSONMergeNode, JSONModifierNode, JSONGeneratorNode, JSONLengthNode, JSONKeyCheckerNode, and JSONStringifierNode. - Updated __init__.py to include new node classes and their display names. - Enhanced README documentation to reflect new features and usage examples. - Bumped version to 1.1.0 in pyproject.toml to signify the addition of new functionalities. This update significantly expands the capabilities of the JSON handling nodes in ComfyUI, providing users with a robust toolkit for JSON data processing.
3.6 KiB
3.6 KiB
ComfyUI JSON管理节点集
为ComfyUI提供的一套功能完整的JSON数据处理节点集合。
功能特点
- 解析和提取JSON数据
- 随机值选择
- JSON对象和数组遍历
- JSON合并和修改
- JSON生成和格式化
- 键值检查和长度计算
安装方法
- 进入ComfyUI自定义节点目录:
cd ComfyUI/custom_nodes/ - 克隆仓库:
git clone git@github.com:Q-Bug4/Comfyui-Json-Nodes.git - 重启ComfyUI或重新加载自定义节点。
可用节点
1. JSON解析器
- 输入:
json_string: JSON字符串path: 数据路径(可选)
- 输出:
parsed_data: 解析后的JSON或特定值array_size: 结果为数组时的长度
2. JSON随机值选择器
- 输入:
json_input: JSON字符串max_depth: 随机选择的最大深度
- 输出:
random_value: 随机选择的值
3. JSON对象迭代器
- 输入:
json_input: JSON对象index: 当前索引mode: 迭代模式(固定/递增/递减)
- 输出:
key: 当前键value: 当前值current_index: 当前位置total_items: 总项目数
4. JSON数组迭代器
- 输入:
json_input: JSON数组index: 当前索引mode: 迭代模式(固定/递增/递减)
- 输出:
item: 当前项current_index: 当前位置total_items: 总项目数
5. JSON合并器
- 输入:
json_input_1: 第一个JSONjson_input_2: 第二个JSONmerge_strategy: 合并策略(覆盖/保留/连接)
- 输出:
merged_json: 合并后的JSON
6. JSON修改器
- 输入:
json_input: 待修改的JSONpath: 修改路径new_value: 新值
- 输出:
modified_json: 更新后的JSON
7. JSON生成器
- 输入:
key_value_pairs: 键值对is_array: 是否生成数组而不是对象
- 输出:
generated_json: 新的JSON结构
8. JSON长度计算器
- 输入:
json_input: JSON输入
- 输出:
length: 项目数量
9. JSON键检查器
- 输入:
json_input: JSON对象key: 待检查的键
- 输出:
exists: 布尔结果value: 存在时的值
10. JSON字符串格式化器
- 输入:
json_input: JSON输入indent: 缩进空格数sort_keys: 是否按字母顺序排序键
- 输出:
json_string: 格式化后的JSON字符串
路径语法
- 嵌套对象:
object.nestedObject.property - 数组元素:
array[0]或array.0 - 复杂结构:
object.array[2].property
使用示例
1. 遍历JSON
# 输入JSON
{
"users": [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]
}
# 使用数组迭代器,mode="incr"
# 将依次输出每个用户对象
2. 合并JSON对象
# 第一个输入
{"name": "John", "age": 30}
# 第二个输入
{"age": 31, "city": "New York"}
# 使用覆盖策略的结果
{"name": "John", "age": 31, "city": "New York"}
3. 随机值选择
# 输入JSON
{
"colors": ["red", "blue", "green"],
"sizes": {"S": 10, "M": 20, "L": 30}
}
# 可能返回任意颜色或尺寸值
错误处理
会在以下情况抛出ValueError:
- 无效的JSON字符串
- 无效的路径或键
- 类型不匹配
- 数组索引越界
参与贡献
欢迎改进!步骤如下:
- Fork本仓库
- 创建新分支
- 进行修改
- 推送到你的Fork
- 提交Pull Request
许可证
MIT许可证。详见LICENSE文件。