1

I've been using the json module in python 2.6 but is very slow. I'd like to use a faster implementation. I've seen cjson but seems the development is not coing on and the api is different from the json module. I have also read some comments about a way to speed up json.

Any ideas?

3
  • 2
    stackoverflow.com/questions/706101/… Commented Mar 1, 2011 at 18:35
  • Thanks. In my linux installation I have json. simplejson and _json. Only the lastone seems to be written in C. Commented Mar 1, 2011 at 18:41
  • This was a known issue in 2.6 and has been fixed. This question is a duplicate of stackoverflow.com/questions/706101/… as Orbit noted, and should be closed. See that question for lots of benchmark data. Commented Apr 26, 2013 at 11:59

2 Answers 2

7

The most recent versions of simplejson are considerably faster than the one built in to python 2.6, and have the same API. If you want your python code to continue working even when simplejson is not installed, try this:

try:
    import simplejson as json
except ImportError:
    import json

See also:

http://bugs.python.org/issue6013

http://bugs.python.org/issue7451

Sign up to request clarification or add additional context in comments.

2 Comments

But what about simplejson._speedups module? Is it used by default or do I need to do something more?
If you build & install the current version of simplejson on a supported platform, speedups will be used automatically.
1

For encoding, you can use iterencode. It uses less memory for the string, so serializing very large data structures takes considerably less time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.