Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Read double serialized json file in Python

I have a json file which has double serialized. The file has been created as:

with open('file.json', 'r') as f:
    file = json.load(f)
#double serializing json file
with open('file_double_serialized.json', "w") as f:
    f.write(json.dumps(json.dumps(file)))

How can I read file_double_serialized.json in Python and create a normal (single-serialized) json file?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just reverse the process:

import json

with open('file_double_serialized.json', "r") as f:
    data = json.loads(json.loads(f.read()))

# write correctly
with open('fixed.json','w') as f:
    json.dump(data,f)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading