Skip to content

TwitchObject is not natively JSON serializable #43

Description

@nklapste

Due to using a datetime.datetime instance in TwitchObject, TwitchObject is not natively JSON serializable.

Example:

json.dumps(client.search.channels("example"))

Running this will result in:

Traceback (most recent call last):
  File ".../twitch-viewer/proto.py", line 17, in <module>
    print(json.dumps(client.search.channels("example")))
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'datetime' is not JSON serializable

Though this can be addressed on the developers end. I feel that a TwitchObject should be able to be easily converted into JSON without additional effort.

A easy solution would be to use a str or int timestamp (eg: from epoc) for dates in a TwitchObject instead of using a datetime.datetime instance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions