class Foo(object):
def __init__(
self,
data_str,
data_int,
data_float,
data_list,
data_n_list,
data_dict,
data_n_dict):
self.str_data = data_str
self.int_data = data_int
self.float_data = data_float
self.list_data = data_list
self.nested_list = data_n_list
self.dictionary = data_dict
self.nested_dictionary = data_n_dict
foo = Foo(
str_data,
int_data,
float_data,
list_data,
nested_list,
dictionary,
nested_dictionary)
# Because the JSON object is a Python dictionary.
result = json.dumps(foo.__dict__, indent=4)
# See table above.
# or with built-in function that accesses .__dict__ for you, called vars()
# result = json.dumps(vars(foo), indent=4)
print(result) # same as before