33 lines
787 B
Python
33 lines
787 B
Python
import json
|
|
|
|
|
|
class DumasJSONStringToObjectNode:
|
|
CATEGORY = "Dumas/JSON"
|
|
RETURN_TYPES = ("JSON",)
|
|
FUNCTION = "convert_string_to_json"
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"json_string": ("STRING", {"multiline": True}),
|
|
}
|
|
}
|
|
|
|
def convert_string_to_json(self, json_string):
|
|
try:
|
|
json_object = json.loads(json_string)
|
|
return (json_object,)
|
|
except json.JSONDecodeError as exc:
|
|
print(f"[DumasNodes] Error decoding JSON: {exc}")
|
|
return (None,)
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
"DumasJSONStringToObject": DumasJSONStringToObjectNode,
|
|
}
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"DumasJSONStringToObject": "Dumas JSON String to Object",
|
|
}
|