0

Working with the Pocket API dataset and trying to parse out details about each item. Unfortunately, I am stuck at looking at "list" data and not the individual details for each item.

JSON

"status": 1,
"complete": 1,
"list": {
    "2872254473": {
        "item_id": "2872254473",
        "resolved_id": "2872254473",
        "given_url": "https://i.redd.it/g0iq3upzffe41.jpg",
        "given_title": "i.redd.it",
        "favorite": "0",
        "status": "1",
        "time_added": "1580666841",
        "time_updated": "1580667500",
        "time_read": "1580667500",
        "time_favorited": "0",
        "sort_id": 0,
        "resolved_title": "",
        "resolved_url": "https://i.redd.it/g0iq3upzffe41.jpg",
        "excerpt": "",
        "is_article": "0",
        "is_index": "0",
        "has_video": "0",
        "has_image": "2",
        "word_count": "0",
        "lang": "",
        "domain_metadata": {
            "name": "Reddit",
            "logo": "https://logo.clearbit.com/reddit.com?size=800",
            "greyscale_logo": "https://logo.clearbit.com/reddit.com?size=800&greyscale=true"
        },

Python Code

import json
with open('2. JSON Data (Pocket Articles Tagged TIL)2.json') as f:
  data = json.load(f)

print(data)
print('----')
print(type(data))
print(type(data['list']))

for item in data['list']:
 print(item)

The issue is I can't seem to use data['item'] or data['list']['item']. I am trying to query the added_date and item_id for each individual item.

3
  • What is the python interpreter output for these prints? Commented Dec 30, 2021 at 19:25
  • there's one more level b/w list and item_id...do data['list']['2872254473']['item_id'] Commented Dec 30, 2021 at 19:26
  • Did you try data['list'][item]? Commented Dec 30, 2021 at 19:38

1 Answer 1

1

You can use following code to get each items id and time_added:

for list_key, value in data['list'].items():
    print(list_key, value['item_id'], value['time_added'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.