Home > OS >  Read double serialized json file in Python
Read double serialized json file in Python

Time:02-21

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?

CodePudding user response:

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)
  • Related