Convert dictionary/array to class (object)

I have found this snippet to convert a JSON string to a class object:

Does anyone know of or have code that converts a dictionary/array to a class object?

Thank you all.

Here is a very naive implementation based on the code above by Nicolò Santilio (without recursion or “frills” I do not understand like property["type"] == 17):

func DictionaryToClass( dict : Dictionary, object : Object ) -> Object:
	var properties : Array = object.get_property_list()

	for key in dict.keys():
		for property in properties:
			if property.name == key:
				object.set( key, dict[ key ] )
				break

	return object
1 Like