'Provide a nicely-formatted JSON Message
@param success: action succeeded or failed
@param status_code: the HTTP status code
@param message: the message text
@param kwargs: other elements for the message
@keyword tree: error tree to include as JSON object (rather
than as string) for easy decoding'

@staticmethod
def json_message(success=True, statuscode=None, message=None, **kwargs):

    if (statuscode is None):
        statuscode = ((success and 200) or 404)
    status = ((success and 'success') or 'failed')
    code = str(statuscode)
    output = {'status': status, 'statuscode': str(code)}
    tree = kwargs.get('tree', None)
    if message:
        output['message'] = s3_unicode(message)
    for (k, v) in kwargs.items():
        if (k != 'tree'):
            output[k] = v
    output = json.dumps(output)
    if (message and tree):
        output = (output[:(-1)] + (',    "tree":    %s}' % tree))
    return output
