Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

from functools import partial 

from json import dumps 

json_dumps = partial(dumps, separators=(",", ":")) 

 

from sanic_restful.util import PY3 

 

from sanic.response import HTTPResponse 

 

 

def output_json(app, data, code, headers=None): 

settings = app.config.get('RESTFUL_JSON', {}) 

dumps = settings.pop('JSON_DUMP', None) or json_dumps 

# If we're in debug mode, and the indent is not set, we set it to a 

# reasonable value here. Note that this won't override any existing value 

# that was set. We also set the "sort_keys" value. 

if app.debug: 

settings.setdefault('indent', 4) 

settings.setdefault('sort_keys', not PY3) 

 

return HTTPResponse( 

dumps(data, **settings) + "\n", 

headers=headers, 

status=200, 

content_type="application/json", 

)