If I have JSON data stored in a string called ‘data’ (e.g. the example below) how do I access specific information (such as messages->unread or pokes->most_recent)?
{
"messages": {
"unread": 0,
"most_recent": 1300047276
},
"pokes": {
"unread": 0,
"most_recent": 0
},
"shares": {
"unread": 0,
"most_recent": 0
},
"friend_requests": [],
"group_invites": [],
"event_invites": []
}
I’d like something like data['messages']['unread'] to work – but of course it won’t when my data is stored as a string!
JSON parser is bundled with Python since 2.6:
jsonmodule. To unserialize a string, usejson.loads, e.g.You can also load directly from a file-like object with
json.load.