views:

50

answers:

0

I've been tyring to figure out how to load JSON objects in Python.

I'm able to send a JSON string to the server, but there it fails.

This is what I'm sending through a websocket with JavaScript:

ws.send('{"test":"test"}');

The server receives it without a problem, but can't validate it:

{"test":"test"}
This is not a JSON object!

Which comes forth from this code:

                    try:
                        data = data[:-1]
                        json.loads(data)
                    except ValueError:
                        print 'This is not a JSON object!'
                    else:
                        print ('JSON found!')

The data = data[:-1] is there to strip the delimiter sent through the websocket.