Serialize to JSON and also dump from the given schema.
(obj, status=200, headers=None, encoder=JSONEncoder)
| 141 | |
| 142 | |
| 143 | def jsonify(obj, status=200, headers=None, encoder=JSONEncoder): |
| 144 | """Serialize to JSON and also dump from the given schema.""" |
| 145 | data = encoder().encode(obj) |
| 146 | mimetype = "application/json" |
| 147 | if "callback" in request.args: |
| 148 | cb = request.args.get("callback") |
| 149 | cb = "".join((c for c in cb if c in CALLBACK_VALID)) |
| 150 | data = "%s && %s(%s)" % (cb, cb, data) |
| 151 | # mime cf. https://stackoverflow.com/questions/24528211/ |
| 152 | mimetype = "application/javascript" |
| 153 | return Response(data, headers=headers, status=status, mimetype=mimetype) |
| 154 | |
| 155 | |
| 156 | def stream_ijson(iterable, encoder=JSONEncoder): |
no test coverage detected