How to JSON serialize sets?

I have a Python set that contains objects with __hash__ and __eq__ methods in order to make certain no duplicates are included in the collection. I need to json encode this result set, but passing even an empty set to the json.dumps method raises a TypeError. File “/usr/lib/python2.7/json/”, line 201, in encode chunks = self.iterencode(o, … Read more

Passing bash variable to jq

I have written a script to retrieve certain value from file.json. It works if I provide the value to jq select, but the variable doesn’t seem to work (or I don’t know how to use it). #!/bin/sh #this works *** projectID=$(cat file.json | jq -r ‘.resource[] | select(.username==”[email protected]”) | .id’) echo “$projectID” [email protected] #this does … Read more

Error message ‘ socket failed: EACCES (Permission denied)’

I get the error message socket failed: EACCES (Permission denied) when I try to apply the code below. This is the function I call and gives me this exception. public void run() { // TODO Auto-generated method stub URL myurl = null; try { myurl = new URL(“”); } catch (MalformedURLException e) { // … Read more

Can’t connect to my WordPress website using Windows 8 app?

Im trying to connect to my WordPress site (self hosted) through the Windows 8 app. First, after giving the account details, it show my site and ask me to Authorize. after authorizing, it say “Can’t connect to the service”. I have used several security plugins in wordpress like the Better WP Security. But they … Read more

Multiple arguments vs. options object

When creating a JavaScript function with multiple arguments, I am always confronted with this choice: pass a list of arguments vs. pass an options object. For example I am writing a function to map a nodeList to an array: function map(nodeList, callback, thisObject, fromIndex, toIndex){ … } I could instead use this: function map(options){ … … Read more

“TypeError: (Integer) is not JSON serializable” when serializing JSON in Python?

I am trying to send a simple dictionary to a json file from python, but I keep getting the “TypeError: 1425 is not JSON serializable” message. import json alerts = {‘upper’:[1425],’lower’:[576],’level’:[2],’datetime’:[‘2012-08-08 15:30’]} afile = open(‘test.json’,’w’) afile.write(json.dumps(alerts,encoding=’UTF-8′)) afile.close() If I add the default argument, then it writes, but the integer values are written to the json … Read more

Where’s my JSON data in my incoming Django request?

I’m trying to process incoming JSON/Ajax requests with Django/Python. request.is_ajax() is True on the request, but I have no idea where the payload is with the JSON data. request.POST.dir contains this: [‘__class__’, ‘__cmp__’, ‘__contains__’, ‘__copy__’, ‘__deepcopy__’, ‘__delattr__’, ‘__delitem__’, ‘__dict__’, ‘__doc__’, ‘__eq__’, ‘__ge__’, ‘__getattribute__’, ‘__getitem__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__iter__’, ‘__le__’, ‘__len__’, ‘__lt__’, ‘__module__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, … Read more