#NEWLINE# def send_json( self , data = None , status = 200 , message = None ) : #NEWLINE# #INDENT# '\n        sends json payload to as a response.\n\n        :param data: Payload to send to client\n        :param status: Status code to send to client\n        ' #NEWLINE# if ( not self ) : #NEWLINE# #INDENT# data = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# self . set_status ( status , self . STATUS [ status ] ) #NEWLINE# output = { #NEWLINE# #INDENT# 'success' : ( status < 300 ) , #NEWLINE# 'payload' : data , #NEWLINE# #UNINDENT# } #NEWLINE# if message : #NEWLINE# #INDENT# output [ 'message' ] = str ( message ) #NEWLINE# #UNINDENT# self . write ( json . dumps ( output ) ) #NEWLINE# self . finish ( )