smiley/steamapi

Get response as real JSON ?

zelds opened this issue · 3 comments

zelds commented
TypeError(repr(o) + " is not JSON serializable")
TypeError: <SteamApp "Need for Speed: Undercover" (17430)> is not JSON serializable

When i try make json.loads(me.games) from example i have error.
json.dumps(me.games) dosen`t help. thx. ?
Is there in lib somthin like (steamapi.user.SteamUser(userurl='test',format='json') ?

Hm, SteamObjects aren't serializable to JSON at the moment. (And the format="json"/automatic_parsing=False option works only if you call APIConnection/APIInterface directly and not use SteamUser, SteamApp, etc.)

It's a bit tricky to JSON-convert these things, since each object has some lazy-loaded items. (Like the list of a game's achievements)

Which parts of me.games do you need as JSON? (That would help me figure out which parts need JSON-exporting support the most)

zelds commented

Thx for answer. As example [{ "Game name": 123, "Game name ": 321}].First string is name and second is game id in steam.
Can now i convert me.games into json ?

For now, you can just do this manually:

>>> me = steamapi.user.SteamUser(123123123123123)
>>> games_json = {}
>>> for game in me.games:
...     games_json[game.name] = game.id
>>> # Or, as a one-liner:
>>> games_json = {game.name: game.id for game in me.games}
>>> json.dumps(games_json)