Add Dumas JSON object iterator node
This commit is contained in:
@@ -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",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user