Skip to content

Instantly share code, notes, and snippets.

@amaciel81
Last active November 21, 2020 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save amaciel81/11a67b175f7e8e4a0b056f5652db9a57 to your computer and use it in GitHub Desktop.
Save amaciel81/11a67b175f7e8e4a0b056f5652db9a57 to your computer and use it in GitHub Desktop.
Import a JSON file. If condition is met, print two attributes.
from json import load as json_load
with open("sample_input.json") as input_fh:
people = json_load(input_fh)
for person in people["people"]:
if person["age"] >= 30:
print("Name: {name}, City: {city}".format(name=person["name"], city=person["city"]))
{
"people":[
{
"name":"John",
"age":30,
"city":"Chicago"
},
{
"name":"Beth",
"age":40,
"city":"New York"
},
{
"name":"Lucy",
"age":25,
"city":"Los Angeles"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment