Add Dumas JSON object iterator node

This commit is contained in:
2026-07-21 10:52:48 +00:00
parent 6994cb64c5
commit 5446a5c068
3 changed files with 75 additions and 0 deletions

View File

@@ -270,6 +270,36 @@ class DumasJSONArrayIteratorNode:
return (json_input[current_index], current_index, total_items)
class DumasJSONObjectIteratorNode:
CATEGORY = "Dumas/JSON"
RETURN_TYPES = ("STRING", "JSON", "INT", "INT")
RETURN_NAMES = ("key", "value", "current_index", "total_items")
FUNCTION = "iterate"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"json_input": ("JSON",),
"index": ("INT", {"default": 0, "min": 0, "step": 1}),
"mode": (["fixed", "incr", "decr"], {"default": "fixed"}),
}
}
def iterate(self, json_input, index, mode):
if not isinstance(json_input, dict):
return (None, None, -1, 0)
items = list(json_input.items())
total_items = len(items)
if total_items == 0:
return (None, None, -1, 0)
current_index = _resolve_iteration_index(index, mode, total_items)
key, value = items[current_index]
return (key, value, current_index, total_items)
NODE_CLASS_MAPPINGS = {
"DumasJSONStringToObject": DumasJSONStringToObjectNode,
"DumasJSONObjectToString": DumasJSONObjectToStringNode,
@@ -279,6 +309,7 @@ NODE_CLASS_MAPPINGS = {
"DumasJSONKeys": DumasJSONKeysNode,
"DumasJSONArrayLength": DumasJSONArrayLengthNode,
"DumasJSONArrayIterator": DumasJSONArrayIteratorNode,
"DumasJSONObjectIterator": DumasJSONObjectIteratorNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -290,4 +321,5 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"DumasJSONKeys": "Dumas JSON Keys",
"DumasJSONArrayLength": "Dumas JSON Array Length",
"DumasJSONArrayIterator": "Dumas JSON Array Iterator",
"DumasJSONObjectIterator": "Dumas JSON Object Iterator",
}