0

I have this script that takes a json data from API and shows me:

import requests
import json

channel_url = requests.get('https://api.nightbot.tv/1/channels/t/gabrigode')
print (channel_url.json())

And returns something like this:

{'status': 200, 'channel': {'_id': '5cfaded67e9c2c215698ae02', 'provider': 'twitch', 'providerId': '125402779', 'name': 'gabrigode', 'displayName': 'GABRIGODE', 'avatar': 'https://static-cdn.jtvnw.net/jtv_user_pictures/4f317068-a036-4f6e-850a-37ef53f3ebca-profile_image-300x300.png', 'joined': True, 'banned': False}}

How i do to take the '_id' value on channel object?

Gabriel
  • 79
  • 8

1 Answers1

1

The json method will return a dictionary of data. It's just key:value pairs. Retrieve them like so:

print(channel_url.json()['channel']['_id'])
gbeaven
  • 1,522
  • 2
  • 20
  • 40