0

so I've got a list of data each element is in this format

{
  "Account_Level": 143,
  "ActiveId1": 8844,
  "ActiveId2": 8879,
  "ActiveId3": 0,
  "ActiveId4": 0,
  "Assists": 14,
  "ret_msg": null
}

this data is pulled from an API wrapper so the type is pyrez.models.Match.Match so when trying to use json.dump to save the list containing this type of data I get

TypeError: Object of type Match is not JSON serializable

EDIT: Fixed using by changing each element individually [i.json for i in session]

  • Does this answer your question? [How to make a class JSON serializable](https://stackoverflow.com/questions/3768895/how-to-make-a-class-json-serializable) – mkrieger1 Jun 13 '20 at 22:01
  • Bey default `json.dump` only understands very basic types like `dict`, `str`, numbers, etc. But, the [the docs](https://docs.python.org/3/library/json.html#json.JSONEncoder.default) you can extend it to serialize other types. That is, you'd pass the `cls` keyword argument as is done in the "Extending JSONEncoder" example near the top of [the docs](https://docs.python.org/3/library/json.html). – Oliver Dain Jun 13 '20 at 22:02

1 Answers1

0

Looks like this PyRez library uses some kind of custom Dict object for API responses, and the __str__ method is already doing a json.dump of the args. So try str(the_obj). See here.

tzaman
  • 46,925
  • 11
  • 90
  • 115