Turning Python Object into a JSON string
<p>I have been working on this bot that takes the twitter api and brings it into my database. Before I was grabbing 1 tweet at a time which wasn't efficient considering I was using 1 request out of the limit they had. So instead I decided to grab 150 results. I get these results back:</p>

<p><code>[Status(ID=780587171757625344, ScreenName=Ampsx, Created=Tue Sep 27 01:57:39 +0000 2016, Text='You know who you are #memes').</code></p>

<p>I get about 150 of these. Is there a library where I can turn this into JSON?</p>

<p>If you're using 2.6+ there's a bundled library you can use (<a href="https://docs.python.org/2.7/library/json.html" rel="nofollow">docs</a>), just:</p>

<pre><code>import json
json_string = json.dumps(object)
</code></pre>

<p>We use this a lot for quick API endpoints, you just need to be careful about having functions or complex nesting in the objects you're trying to serialize, it's quite configurable (so you can skip fields, customize output of some, etc.) but can get messy pretty quickly.</p>

python json