Which JSON module can I use in Python 2.5?

PythonJson

Python Problem Overview


I would like to use Python's http://docs.python.org/library/json.html">JSON</a> module. It was only introduced in Python 2.6 and I'm stuck with 2.5 for now. Is the particular JSON module provided with Python 2.6 available as a separate module that can be used with 2.5?

Python Solutions


Solution 1 - Python

You can use simplejson.

As shown by the answer form pkoch you can use the following import statement to get a json library depending on the installed python version:

try:
    import json
except ImportError:
    import simplejson as json 

Solution 2 - Python

To Wells and others: > Way late here, but how can you write a script to import either json or simplejson depending on the installed python version?

Here's how:

try:
import json
except ImportError:
import simplejson as json

Solution 3 - Python

I wrote the cjson 1.0.6 patch and my advice is don't use cjson -- there are other problems with cjson in how it handles unicode etc. I don't think the speed of cjson is worth dealing with the bugs -- encoding/decoding json is usually a very small bit of the time needed to process a typical web request...

json in python 2.6+ is basically simplejson brought into the standard library I believe...

Solution 4 - Python

I prefer cjson since it's much faster: http://www.vazor.com/cjson.html

Solution 5 - Python

I am programming in Python 2.5 as well and wanted a suitable library. Here is how I did it.

donwloaded the simplejson egg file called simplejson-2.0.6-py2.5-linux-i686.egg from http://pypi.python.org/simple/simplejson/

installed it using the command :

sudo python ./ez_setup.py ./simplejson-2.0.6-py2.5-linux-i686.egg

Then imported the json library into the script file by doing :

import sys
sys.path.append("/home/coolkid/Android/simplejson/simplejson-2.0.6-py2.5-linux-i686.egg")
try: import simplejson as json
except ImportError: print ("import error")

Solution 6 - Python

json is a built-in module, you don't need to install it with pip.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmoinudinView Question on Stackoverflow
Solution 1 - PythonscottynomadView Answer on Stackoverflow
Solution 2 - PythonpkochView Answer on Stackoverflow
Solution 3 - PythonMatt BillensteinView Answer on Stackoverflow
Solution 4 - PythonDavidView Answer on Stackoverflow
Solution 5 - PythonSrinivas RaoView Answer on Stackoverflow
Solution 6 - PythonShriganesh KolheView Answer on Stackoverflow