Parsing comma separated JSON from a file

前端 未结 2 647
执笔经年
执笔经年 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:14

    you can parse the data to dict by following this link. Parsing values from a JSON file using Python?

    and convert the dict to list by the

    .items()
    

    function to the parsed dictionary.

    Hope this one solves the problem. Good luck.

    0 讨论(0)
  • 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))
    
    0 讨论(0)
提交回复
热议问题