Fix Python – Serializing class instance to JSON

I am trying to create a JSON string representation of a class instance and having difficulty. Let’s say the class is built like this:
class testclass:
value1 = “a”
value2 = “b”

A call to the json.dumps is made like this:
t = testclass()
json.dumps(t)

It is failing and telling me that the testclass is not JSON serializable.
TypeError: <__....

Fix Python – How to get string objects instead of Unicode from JSON?

I’m using Python 2 to parse JSON from ASCII encoded text files.
When loading these files with either json or simplejson, all my string values are cast to Unicode objects instead of string objects. The problem is, I have to use the data with some libraries that only accept string objects. I can’t change the libraries nor update them.
Is it possib….

Fix Python – Convert a python dict to a string and back

I am writing a program that stores data in a dictionary object, but this data needs to be saved at some point during the program execution and loaded back into the dictionary object when the program is run again.
How would I convert a dictionary object into a string that can be written to a file and loaded back into a dictionary object? This will ….