【发布时间】:2018-07-11 17:57:47
【问题描述】:
我有一个简单的 python 3.6 程序,它使用 Boto3 库下载 AWS S3 JSON 文件
import boto3
import json
s3 = boto3.resource('s3')
content_object = s3.Object('my-bucket-name', 'folder1/folder2/emr-config.json')
file_content = content_object.get()['Body'].read().decode('utf-8')
json_content = json.loads(file_content)
print(json_content)
但是程序正在将 JSON 文件中使用的 " 双引号更改为 ' 单引号,即,当我直接从 AWS 管理控制台下载文件时,JSON 使用 " 双引号,但是当我运行我的程序并打印出生成的 JSON 它使用 ' 单引号。
[{'Properties': {'maximizeResourceAllocation': 'true'}, 'Classification': 'spark'}]
对比
[{"Properties": {"maximizeResourceAllocation": "true"}, "Classification": "spark"}]
这是我将用于创建 EMR 集群的配置文件,它仅在 JSON 配置使用“双引号”时才有效。
我想找到一个不涉及我对整个文件进行查找和替换的解决方案。有没有办法让我以“双引号”形式下载文件?
【问题讨论】:
标签: json python-3.x amazon-s3 boto3