Convert Tweepy Status object into JSON

KOM picture KOM · Jan 12, 2015 · Viewed 34.8k times · Source

I'm using Tweepy to download tweets. I have a program that then writes the actual Status object to a file in text form. How do I translate this into JSON, or import this object back into Python? I've tried using the JSON library to encode, but Status is not JSON serializable.

Answer

taskinoor picture taskinoor · Jan 12, 2015

The Status object of tweepy itself is not JSON serializable, but it has a _json property which contains JSON serializable response data. For example:

>>> status_list = api.user_timeline(user_handler)
>>> status = status_list[0]
>>> json_str = json.dumps(status._json)