use flask.jsonify instead of custom json encode function

I removed boilerplate code and used flask.jsonify instead. The only difference is that the json output is pretty printed (this may be good for debugging) but this could be parameterized if you don't want it.