Skip to content

Instantly share code, notes, and snippets.

flatten_list=lambda l: sum(map(flatten_list,l),[]) if isinstance(l,list) else [l]
def flatten_json(json_r):
normal = {x: y for x,y in json_r.items() if not isinstance(y, dict)}
dict_value = [(x, y) for x,y in json_r.items() if isinstance(y, dict)]
if bool(dict_value):
new_dict = {".".join([str(value[0]), str(x)]): value[1][x] for value in dict_value for x in value[1]}
normal.update(new_dict)
return flatten_json(normal)
@jamshedazhar
jamshedazhar / fix_content_type_s3.py
Created June 22, 2018 12:27
Sample script to fix ContentType of object stored in AWS S3.
import boto3
s3 = boto3.client('s3')
bucket_name = '<bucket name>'
valid_content_type = ['image/jpeg', 'image/png', 'image/gif']
def is_valid_header(bucket, key):
try: