Parsing comma separated JSON from a file

前端 未结 2 680
执笔经年
执笔经年 2021-01-25 15:07

I am reading a file that contains JSON separated by commas. So for example

{
  ...JSON
},
{
  ...JSON
},
{
  ...JSON
}

I know for sure they are

2条回答
  •  醉酒成梦
    2021-01-25 15:33

    That's not valid JSON, it is missing the [...] brackets to make it a list.

    You could add those manually:

    with open(source_file) as source:
        json_source = source.read()
        data = json.loads('[{}]'.format(json_source))
    

提交回复
热议问题