Read s3 files (JSON)

PHOTO EMBED

Wed May 29 2024 09:53:52 GMT+0000 (Coordinated Universal Time)

Saved by @krishna01 ##read_s3 ##read_files_from_s3_json ##read_ocr_from_s3

import boto3
import json

def read_ocr_from_s3(bucket_name, key_name):
    s3 = boto3.client('s3')
    response = s3.get_object(Bucket=bucket_name, Key=key_name)
    ocr_data = json.loads(response['Body'].read().decode('utf-8'))
    return ''.join([item["text"] for item in ocr_data])
content_copyCOPY