Answers for "python json api"

14

api in python

import requests
import json

r = requests.get("URL")
j=r.json()
print(j)
Posted by: Guest on February-19-2020
1

json load

import json

with open('path_to_file/person.json') as f:
  data = json.load(f)
Posted by: Guest on October-27-2020
0

python json rest api tutorial

>>> import requests
>>> import json
>>> api_url = "https://jsonplaceholder.typicode.com/todos"
>>> todo = {"userId": 1, "title": "Buy milk", "completed": False}
>>> headers =  {"Content-Type":"application/json"}
>>> response = requests.post(api_url, data=json.dumps(todo), headers=headers)
>>> response.json()
{'userId': 1, 'title': 'Buy milk', 'completed': False, 'id': 201}

>>> response.status_code
201
Posted by: Guest on October-01-2021

Python Answers by Framework

Browse Popular Code Answers by Language