Home » Jquery » jquery – Get value from JSON in Python

jquery – Get value from JSON in Python

Posted by: admin February 22, 2020 Leave a comment


I want to assign get the value of “feels_like” and assign it to a new variable. How can I do it?

test({"coord":{"lon":-71.06,"lat":42.36},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"base":"stations","main":{"temp":1.69,"feels_like":-1.22,"temp_min":0,"temp_max":3.33,"pressure":1013,"humidity":94},"visibility":16093,"wind":{"speed":1.5,"deg":230},"rain":{"1h":0.25},"clouds":{"all":90},"dt":1582094044,"sys":{"type":1,"id":3413,"country":"US","sunrise":1582112159,"sunset":1582150834},"timezone":-18000,"id":4930956,"name":"Boston","cod":200})
How to&Answer:

you can do that as follows:

d = {"coord": {"lon": -71.06, "lat": 42.36}, "weather": [{"id": 500, "main": "Rain", "description": "light rain", "icon": "10n"}], "base": "stations", "main": {"temp": 1.69, "feels_like": -1.22, "temp_min": 0, "temp_max": 3.33, "pressure": 1013, "humidity": 94}, "visibility": 16093, "wind": {
    "speed": 1.5, "deg": 230}, "rain": {"1h": 0.25}, "clouds": {"all": 90}, "dt": 1582094044, "sys": {"type": 1, "id": 3413, "country": "US", "sunrise": 1582112159, "sunset": 1582150834}, "timezone": -18000, "id": 4930956, "name": "Boston", "cod": 200}
feels = d["main"]["feels_like"]

Hope it helps you!


If you are loading this from a file, you can use the json package to load the file into a python dictionary. You can then manipulate the dictionary the way you normally do.

See https://docs.python.org/3/library/json.html