How to handle Json response and How Can I sperate value from this Json response in my terminal window

Samir Paruthi
`import requests
from requests.models import Response

api_key = "xxx"
city = "Houston"
Response = requests.get(
    f"https://api.openweathermap.org/data/2.5/weather?q={city},us&appid={api_key}")

full_info = (Response.json()["weather"])

print(full_info)`

Output:

{'coord': {'lon': -95.3633, 'lat': 29.7633}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}], 'base': 'stations', 'main': {'temp': 299.96, 'feels_like': 302.81, 'temp_min': 298.12, 'temp_max': 301.26, 'pressure': 1015, 'humidity': 84}, 'visibility': 10000, 'wind': {'speed': 0.89, 'deg': 231, 
'gust': 4.02}, 'clouds': {'all': 1}, 'dt': 1627897632, 'sys': {'type': 2, 'id': 2006306, 'country': 'US', 'sunrise': 1627904498, 'sunset': 1627953218}, 'timezone': -18000, 'id': 4699066, 'name': 'Houston', 'cod': 200}

if I use full_info = response.json()["weather"]

Output: [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01n'}] after checking its type its list but I am unable to access specific keyvalue Like Main, or description

How I can achieve all value in different variable or can access only which I want

if I try printing using index

print(full_info[0])

output remains the same

Binit

Do full_info = Response.json() and then

print(full_info['weather'][0]['id'])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to get JSON value from HTTP response?

How to extract a single value from JSON response?

How can i loop the response of my JSON Object?

How can I check if my response is a string or JSON Object?

How can I return a value from a function that uses json response?

How can I properly read json data from ajax response?

How to properly handle error from json response

How can I extract response from json array in Karate

How can I count boolean value from JSON response in swift

How can I access this json response object?

How can I reach a specific data from JSON response in flutter?

how can I get the key and value from a multidimensional json response using php

How can I destructure a JSON response into a table?

How To get the value from a Json response

How can I wrap a JSON response in Spring

How to extract a value from this JSON response

How can i remove particular data from JSON response

How can i get json key and value from autocomplete response in separate textbox. please see image

How can i extract the value of "token" from this JSON response with Java

How to extract an exact value from a response in Json?

how can i Extract JSON from HTTP Response (python)

How can I show JSON response in my Snackbar?

How can I get the snippet info from my api json response?

How can I get JSON response from Github Api?

How to handle response from JSON but started with numbers

How can I extract specific value from JSON response?

How can I access a specific value from a JSON response in C# .net?

How can I get the value on a position from a JSON Response on Android Studio?

How can I verify json response in Karate?

TOP Ranking

HotTag

Archive