simplejson

Reading JSON from SimpleHTTPServer Post data

Reading JSON from SimpleHTTPServer Post data Question: I am trying to build a simple REST server with python SimpleHTTPServer. I am having problem reading data from the post message. Please let me know if I am doing it right. from SimpleHTTPServer import SimpleHTTPRequestHandler import SocketServer import simplejson class S(SimpleHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header(‘Content-type’, ‘text/html’) self.end_headers() …

Total answers: 2

simplejson returns values not in order

simplejson returns values not in order Question: When working with simplejson in Django, I sometimes need to send the information strictly in order. values = {“entry1″:”value1″,”entry2″:”value2″,”entry3″:”value3″} return HttpResponse(simplejson.dumps(values),content_type=”application/json”) That’s what it returns {“entry2”: “value2”, “entry3”: “value3”, “entry1”: “value1”} But I want it to returns this instead: {“entry1″:”value1″,”entry2″:”value2″,”entry3″:”value3”} How can I send the information in order …

Total answers: 4

Simplejson error Python 3.3

Simplejson error Python 3.3 Question: I’m trying to run a program that imports simplejson. When I run it in Python 2.7 it’s ok, but when I run it in Python 3.3 it says: File “C:Python33libsimplejson__init__.py”, line 111, in <module> from decoder import JSONDecoder, JSONDecodeError ImportError: No module named ‘decoder’ Asked By: user3017348 || Source Answers: …

Total answers: 2

Getting values from JSON using Python

Getting values from JSON using Python Question: While I am trying to retrieve values from JSON string, it gives me an error: data = json.loads(‘{“lat”:444, “lon”:555}’) return data[“lat”] But, if I iterate over the data, it gives me the elements (lat and lon), but not the values: data = json.loads(‘{“lat”:444, “lon”:555}’) ret = ” for …

Total answers: 5

Python JSON module has no attribute 'dumps'

Python JSON module has no attribute 'dumps' Question: 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: …

Total answers: 10

SimpleJSON and NumPy array

SimpleJSON and NumPy array Question: What is the most efficient way of serializing a numpy array using simplejson? Asked By: epoch || Source Answers: I’d use simplejson.dumps(somearray.tolist()) as the most convenient approach (if I was still using simplejson at all, which implies being stuck with Python 2.5 or earlier; 2.6 and later have a standard …

Total answers: 9

Easiest way to serialize a simple class object with simplejson?

Easiest way to serialize a simple class object with simplejson? Question: I’m trying to serialize a list of python objects with JSON (using simplejson) and am getting the error that the object “is not JSON serializable”. The class is a simple class having fields that are only integers, strings, and floats, and inherits similar fields …

Total answers: 7

Get json data via url and use in python (simplejson)

Get json data via url and use in python (simplejson) Question: I imagine this must have a simple answer, but I am struggling: I want to take a url (which outputs json) and get the data in a usable dictionary in python. I am stuck on the last step. >>> import urllib2 >>> import simplejson …

Total answers: 3

Python JSON encoding

Python JSON encoding Question: I’m trying to encode data to JSON in Python and I been having a quite a bit of trouble. I believe the problem is simply a misunderstanding. I’m relatively new to Python and never really got familiar with the various Python data types, so that’s most likely what’s messing me up. …

Total answers: 7