Skip to content

Instantly share code, notes, and snippets.

@dfetterman
Created June 11, 2019 15:27
Show Gist options
  • Save dfetterman/fa7e05e87769cdb58c7bcda6e83407d1 to your computer and use it in GitHub Desktop.
Save dfetterman/fa7e05e87769cdb58c7bcda6e83407d1 to your computer and use it in GitHub Desktop.
Parse s3 json object
[
{
"clientName": "BobSmith",
"clientID": "22oi5qjafaflklkjklajlf",
"postconf": "CanvasCatalog",
"group": "MRH3"
},
{
"clientName": "ToddHarris",
"clientID": "i5qj3klq23rhljkna.nmaf",
"postconf": "CanvasCatalog",
"group": "LAR"
}
]
import json
import boto3
s3_obj =boto3.client('s3')
s3_clientobj = s3_obj.get_object(Bucket='dane-fetterman-bucket', Key='mydata.json')
s3_clientdata = s3_clientobj['Body'].read().decode('utf-8')
print("printing s3_clientdata")
print(s3_clientdata)
print(type(s3_clientdata))
s3clientlist=json.loads(s3_clientdata)
print("json loaded data")
print(s3clientlist)
print(type(s3clientlist))
#print(s3clientlist[0]['clientName'])
loclientdict=next(item for item in s3clientlist if item["clientID"] == "22oi5qjafaflklkjklajlf")
print(loclientdict)
group=loclientdict.get('group')
print(group)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment