Retrieving JSON objects from a text file (using Python)

后端 未结 9 1610
失恋的感觉
失恋的感觉 2020-11-30 04:50

I have thousands of text files containing multiple JSON objects, but unfortunately there is no delimiter between the objects. Objects are stored as dictionaries and some of

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 05:50

    Replace a file with that junk in it:

    $ sed -i -e 's;}{;}, {;g' foo
    

    Do it on the fly in Python:

    junkJson.replace('}{', '}, {')
    

提交回复
热议问题