Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace simplejson with json in django python?

Tags:

python

django

I have the following code in my views:

def __init__(self, obj='', json_opts={}, mimetype="application/json", *args, **kwargs):
        content = simplejson.dumps(obj, **json_opts)
        super(JSONResponse, self).__init__(content, mimetype, *args, **kwargs)

Since simplejson is going to be deprecated, can i use this

content = json.dumps(obj, **json_opts)

or do I need to do more?

like image 401
Mirage Avatar asked Oct 22 '12 05:10

Mirage


2 Answers

Use python's json instead:

Django 1.5 release notes

import json
like image 196
Max Gruzin Avatar answered Sep 18 '22 22:09

Max Gruzin


According to this answer, json is simplejson. However, according to this release note, there might be some incompatibilities depending on which version of simplejson you are currently using. Either way, you will want to replace simplejson with json at some point. Just make sure you test your code before pushing it out to production.

like image 24
Garrett Hyde Avatar answered Sep 18 '22 22:09

Garrett Hyde