0

I am trying to access objects in S3 bucket which is a JSON file and tying to open it up in Visual Studio code. But I am getting error "json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig)"

import boto3
import json
import requests
boto3.setup_default_session(profile_name='rli-dev', region_name='us-west-2')
s3 = boto3.resource('s3')
content_object = s3.Object('bsdev-data-validation','awsnightlyendtoend_bsdev_2018-10-24T11:53:45Z/validate_adwactivityfact/job-details.json')

file_content = content_object.get()['Body'].read().decode()
json_content = json.loads(file_content)
print(json_content)
Ryan
  • 39
  • 1
  • 10

1 Answers1

0

default encoding for decode() is utf-8. The traceback specify the encoding of the file is utf-8 BOM thus you need to pass utf-8-sig to decode(), e.g.

file_content = content_object.get()['Body'].read().decode('utf-8-sig')
buran
  • 13,682
  • 10
  • 36
  • 61