Reading a JSON File

Learn how to read a JSON file stored in a Filebase bucket using Python & Boto3.

What is JSON?

JSON is a file format featuring an open standard and interchangeable data format that uses human-readable text to store and transmit data objects that are formatted as arrays or value pairs.

Read below to learn how to use a Python script with Boto3 to read the contents of a JSON file that is stored in a Filebase bucket.

Prerequisites:

1. Create a file called json_read.py with the following contents:

import boto3
import json
from botocore.config import Config

boto_config = Config(region_name = 'us-east-1',
signature_version = 's3v4')
s3 = boto3.client('s3',
	endpoint_url = 'https://s3.filebase.com',
	aws_access_key_id='filebase-access-key',
	aws_secret_access_key='filebase-secret-key',
	config=boto_config)

object = s3.get_object(Bucket='filebase-sample-bucket',Key='my_file.json')
j = json.loads(object['Body'].read())
print(j['Details'])

2. Replace the following values:

  • Aws_access_key_id: Your Filebase Access Key

  • Aws_secret_access_key: Your Filebase Secret Key

  • Bucket: Your Filebase bucket name

  • Key: Your JSON file to be read

  • Replace ‘Details’ with the name of the property in your JSON file to read

3. Run the Python script to return the requested JSON property content.

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated