I am running Python 2.7 (x64 Linux) and trying to convert a dict
to a JSON object.
>>> import sys
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=0, releaselevel='final', serial=0)
I am trying to use simplejson
(falling back to json
from the standard library) but I get the following error:
>>> try: import simplejson as json
... except ImportError: import json
...
>>> metadata = dict()
>>> metadata['foo'] = 'bar'
>>> print metadata
{'foo': 'bar'}
>>> json.dumps(metadata)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dumps'
Is there something obvious I am missing about using json
or simplejson
with Python 2.7?
print json.__file__
? – Hildahildagard