简体   繁体   English

将多个JSON对象写入一个.json文件

[英]Writing multiple JSON objects into one .json file

I'm writing a python script to run through a csv file and convert it into one .json file. 我正在编写一个Python脚本来运行一个csv文件,并将其转换为一个.json文件。 That would mean the .json file would have multiple json objects inside it. 这意味着.json文件中将包含多个json对象。 I've got most of the script working but the part I am confused with (and I've looked online for a while now) is how multiple JSON objects should be stored in one .json file. 我已经完成了大部分脚本的工作,但令我感到困惑的部分(并且我已经在线寻找了一段时间)是如何在一个.json文件中存储多个JSON对象。 Is it either of the ways below? 是下面两种方式之一吗? :

{
    "index": {
        "_index": "jobs", 
        "_id": 119556, 
        "_type": "2014_jobs"
    },
    "index2": {
        "_index": "jobs", 
        "_id": 119700, 
        "_type": "2014_jobs"
    },
    "index3": {
        "_index": "jobs", 
        "_id": 118701, 
        "_type": "2014_jobs"
    },           
}

or 要么

{"index": {"_index": "jobs", "_id": 119556, "_type": "2014_jobs"}}
{"index2": {"_index": "jobs", "_id": 119700, "_type": "2014_jobs"}}
{"index3": {"_index": "jobs", "_id": 118701, "_type": "2014_jobs"}}

Looks pritty close to the solution. 看起来很接近解决方案。 May you should use a list: 可以使用以下列表:

{
 "data":[
    {
        "_index": "jobs", 
        "_id": 119556, 
        "_type": "2014_jobs"
    },
    {
        "_index": "jobs", 
        "_id": 119700, 
        "_type": "2014_jobs"
    },
    {
        "_index": "jobs", 
        "_id": 118701, 
        "_type": "2014_jobs"
    }]           
}

This would be my solution. 这将是我的解决方案。 Hope it helped 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM