如何将两个字典组合成一个json文件,两个字典之间有换行符?

wkftcu5l  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(0)|浏览(159)

我有两个用python创建的字典,我想把它转换成elasticsearch json格式。
下面是我要转换的示例json(bulk\u movies.json)格式的链接:https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg-upload-data.html
以下是两本词典:

dic1 = {'index': {'_index': 'movies', '_id': '1'}
dic2 = {'id': '1', 'year': '2009'}

我使用以下代码将数据导入json文件。然而,这两部词典是同一条线。

with open(file, 'w') as fd:
    fd.write(json.dumps([dic1, dic2]))

实际输出:

[{'index': {'_index': 'movies', '_id': '1'}}, {'id': '1', 'year': '2009'}]

所需输出:

{'index': {'_index': 'movies', '_id': '1'}
{'id': '1', 'year': '2009'}

如果有人能帮我,那就太好了!!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题