<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def encode(self, obj):
 """Returns ``obj`` serialized as JSON formatted bytes. Raises ------ ~ipfsapi.exceptions.EncodingError Parameters obj : str | list | dict | int JSON serializable Python object Returns ------- bytes """

        try:
            result = json.dumps(obj, sort_keys=True, indent=None,
                                separators=(',', ':'), ensure_ascii=False)
            if isinstance(result, six.text_type):
                return result.encode("utf-8")
            else:
                return result
        except (UnicodeEncodeError, TypeError) as error:
            raise exceptions.EncodingError('json', error)