본문 바로가기

Python_Intermediate/Json

JSON - Basic 예제

반응형

1. URL : http://api.github.com/users/ankiwoong  

 

2. Code

import requests
res = requests.get('http://api.github.com/users/ankiwoong')

print(type(res))

<class 'requests.models.Response'>

Process finished with exit code 0

 

import requests
res = requests.get('http://api.github.com/users/ankiwoong')

text = res.text
print(text)

{"login":"ankiwoong","id":51388721,"node_id":"MDQ6VXNlcjUxMzg4NzIx","avatar_url":"https://avatars3.githubusercontent.com/u/51388721?v=4","gravatar_id":"","url":"https://api.github.com/users/ankiwoong","html_url":"https://github.com/ankiwoong","followers_url":"https://api.github.com/users/ankiwoong/followers","following_url":"https://api.github.com/users/ankiwoong/following{/other_user}","gists_url":"https://api.github.com/users/ankiwoong/gists{/gist_id}","starred_url":"https://api.github.com/users/ankiwoong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankiwoong/subscriptions","organizations_url":"https://api.github.com/users/ankiwoong/orgs","repos_url":"https://api.github.com/users/ankiwoong/repos","events_url":"https://api.github.com/users/ankiwoong/events{/privacy}","received_events_url":"https://api.github.com/users/ankiwoong/received_events","type":"User","site_admin":false,"name":"AnKiwoong","company":"TCTD Coding","blog":"https://developer-ankiwoong.tistory.com/","location":"Seoul, Korea","email":null,"hireable":null,"bio":"Hi.\r\nI am a beginner development \r\ncomputer assistant. Please note a lot.","public_repos":3,"public_gists":0,"followers":0,"following":0,"created_at":"2019-06-05T00:25:18Z","updated_at":"2019-07-26T07:54:34Z"}

Process finished with exit code 0

 

import requests
import pprint
res = requests.get('http://api.github.com/users/ankiwoong')

text = res.text

pprint.pprint(res.text)

('{"login":"ankiwoong","id":51388721,"node_id":"MDQ6VXNlcjUxMzg4NzIx","avatar_url":"https://avatars3.githubusercontent.com/u/51388721?v=4","gravatar_id":"","url":"https://api.github.com/users/ankiwoong","html_url":"https://github.com/ankiwoong","followers_url":"https://api.github.com/users/ankiwoong/followers","following_url":"https://api.github.com/users/ankiwoong/following{/other_user}","gists_url":"https://api.github.com/users/ankiwoong/gists{/gist_id}","starred_url":"https://api.github.com/users/ankiwoong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankiwoong/subscriptions","organizations_url":"https://api.github.com/users/ankiwoong/orgs","repos_url":"https://api.github.com/users/ankiwoong/repos","events_url":"https://api.github.com/users/ankiwoong/events{/privacy}","received_events_url":"https://api.github.com/users/ankiwoong/received_events","type":"User","site_admin":false,"name":"AnKiwoong","company":"TCTD '
 'Coding","blog":"https://developer-ankiwoong.tistory.com/","location":"Seoul, '
 'Korea","email":null,"hireable":null,"bio":"Hi.\\r\\nI am a beginner '
 'development \\r\\ncomputer assistant. Please note a '
 'lot.","public_repos":3,"public_gists":0,"followers":0,"following":0,"created_at":"2019-06-05T00:25:18Z","updated_at":"2019-07-26T07:54:34Z"}')

Process finished with exit code 0

 

import requests
import pprint
res = requests.get('http://api.github.com/users/ankiwoong')

pprint.pprint(res.json())

{'avatar_url': 'https://avatars3.githubusercontent.com/u/51388721?v=4',
 'bio': 'Hi.\r\n'
        'I am a beginner development \r\n'
        'computer assistant. Please note a lot.',
 'blog': 'https://developer-ankiwoong.tistory.com/',
 'company': 'TCTD Coding',
 'created_at': '2019-06-05T00:25:18Z',
 'email': None,
 'events_url': 'https://api.github.com/users/ankiwoong/events{/privacy}',
 'followers': 0,
 'followers_url': 'https://api.github.com/users/ankiwoong/followers',
 'following': 0,
 'following_url': 'https://api.github.com/users/ankiwoong/following{/other_user}',
 'gists_url': 'https://api.github.com/users/ankiwoong/gists{/gist_id}',
 'gravatar_id': '',
 'hireable': None,
 'html_url': 'https://github.com/ankiwoong',
 'id': 51388721,
 'location': 'Seoul, Korea',
 'login': 'ankiwoong',
 'name': 'AnKiwoong',
 'node_id': 'MDQ6VXNlcjUxMzg4NzIx',
 'organizations_url': 'https://api.github.com/users/ankiwoong/orgs',
 'public_gists': 0,
 'public_repos': 3,
 'received_events_url': 'https://api.github.com/users/ankiwoong/received_events',
 'repos_url': 'https://api.github.com/users/ankiwoong/repos',
 'site_admin': False,
 'starred_url': 'https://api.github.com/users/ankiwoong/starred{/owner}{/repo}',
 'subscriptions_url': 'https://api.github.com/users/ankiwoong/subscriptions',
 'type': 'User',
 'updated_at': '2019-07-26T07:54:34Z',
 'url': 'https://api.github.com/users/ankiwoong'}

Process finished with exit code 0

반응형