Unfortunately, not at the moment. I myself have run across this issue lately. We really need to make the Indigo versions more easily serialized such that json would just work, and it's on the list of things to consider moving forward.
While I haven't thoroughly tested yet, I think this function should recursively convert any Indigo.Dict or Indigo.List (starting with one of those as the initial argument) to a native python hierarchy which can then be serialized as necessary:
- Code: Select all
def convert_to_native(obj):
if isinstance(obj, indigo.List):
native_list = list()
for item in obj:
native_list.append(convert_to_native(item))
return native_list
elif isinstance(obj, indigo.Dict):
native_dict = dict()
for key, value in obj.items():
native_dict[key] = convert_to_native(value)
return native_dict
else:
return obj
A few obvious restrictions: the first object passed in should be an indigo.Dict or an indigo.List object, and any python containers (list or dict for instance) that themselves contain indigo.List or indigo.Dict objects won't be converted. Basically, if you've managed to mix and match throughout the hierarchy the function will likely not work for you. It could be altered to deal with that scenario of course, but my needs didn't require it.
This obviously doesn't convert the other way either since I haven't found the need yet.
In any case, maybe this will help you along the way.