python - 如何将多记录多行 JSON 转换为 AWS Athena 的每记录 JSON 单行?
问题描述
我想在 AWS Athena 中使用 json 文件,但 Athena 不支持多行 JSON。
我有以下(其中一个值是 XML)
{
"id" : 10,
"name" : "bob",
"data" : "<some> \n <xml> \n <in here>"
},
{
"id" : 20,
"name" : "jane",
"data" : "<other> \n <xml> \n <in here>"
}
我需要以下雅典娜
{ "id" : 10, "name" : "bob", "data" : "<some> <xml> <in here>" },
{ "id" : 20, "name" : "jane", "data" : "<other> <xml> <in here>" }
我正在使用 RazorSQL 从 DB2 中导出数据,并尝试使用 Python 编写一些代码来“扁平化”它,但还没有成功。
谢谢!
解决方案
我最终做了一些快速而肮脏的事情
import json
with open('data.json') as jfile:
data = json.load(jfile)
for d in data:
print(json.dumps(d) + ',')
哪个打印
{'id': 200, 'name': 'bob', 'data': '<other> \n <xml> \n <data>'},
{"id": 200, "name": "bob", "data": "<other> \n <xml> \n <data>"},
刚刚将输出保存到另一个文件:P
它失败了,因为文件太大了,但是嘿..很接近!
推荐阅读
- python - 使导入工作从不同的路径执行
- python - 如何使用特定值中的值来查找索引python
- python - 我正在尝试在 python/pandas 中将多行组合成单行
- javascript - '$' 未在 JavaScript 中定义
- ckeditor - 如何允许通过 URL 插入图像但不允许上传?
- nosql - 有没有办法强制在 Oracle NoSQL 数据库的查询中首先使用特定的二级索引?
- python - 无法在 try-except 结构中编译并返回 Python 函数
- node.js - 为什么我无法访问此 node.js 应用程序中的 HTTP 调用?
- android - 每当我尝试在 Firestore 上打开特定文档时,Firestore 控制台就会打开。仅在我单击特定文档时发生
- python - 将元组转换为熊猫数据框