import json
FILE_NAME = "helium.json"
# Can expand to multiple lines
he = json.loads(open(FILE_NAME).read())Thinking Machines
[]).number):get() Method[] causes a KeyError and crashes..get..values() method to iterate only through the values in the dictionary..items() method returns a tuple of (key, value) for each pair, which you can unpack in the loop.{ and ends with }.:). Pairs are separated by commas (,).requestsimport requests
URL = "https://cd-public.github.io/scicom/helium.json"
response = requests.get(URL)
# vax_data is now a Python list of dictionaries
he = response.json()
he # Note that "number" is gone - we have the original file again.{'symbol': 'He',
'phase_stp': 'gas',
'group': 18,
'period': 1,
'boiling_point': {'K': 4.222, 'C': -268.928, 'F': -452.07}}
"country": name and "iso_code": whatever that is"data", a list of
"date": a date as a string, like "2021-02-22"[ and ends with ].,).[{'date': '2021-02-22',
'total_vaccinations': 0,
'people_vaccinated': 0,
'total_vaccinations_per_hundred': 0.0,
'people_vaccinated_per_hundred': 0.0},
{'date': '2021-02-23',
'daily_vaccinations': 1367,
'daily_vaccinations_per_million': 33,
'daily_people_vaccinated': 1367,
'daily_people_vaccinated_per_hundred': 0.003},
{'date': '2021-02-24',
'daily_vaccinations': 1367,
'daily_vaccinations_per_million': 33,
'daily_people_vaccinated': 1367,
'daily_people_vaccinated_per_hundred': 0.003}]
"Olive Drab".
7 or 3.14.true or false.
True and FalseNone{}[]vax file is one single JSON array."data"."data" is an array of daily vaccination records.
").{ 'country': 'Elysium' } (Uses single quotes).{ "country": "Cascadia" }null are NOT quoted.null.null becomes None.None before trying to perform arithmetic or string operations.json.dump() to write a Python object (dict or list) to a file.json.dumps() to convert it to a JSON formatted string.indent argument makes the JSON human-readable for debugging or configuration files."population": 331002651."daily_vaccinations_per_hundred": 0.52.{}) and arrays ([]).json library and the requests.json() method are your primary tools.null values.