I have a part of the code for saving a nested dictionary into a json file with indentation 6, now in another program I have to read the same file and save it into a dictionary. It is failing.
This is the code snippet for saving
out_file = open("myfile.json", "w") json.dump(master, out_file, indent = 6) out_file.close() The code snippet I am using for reading it
with open('myfile.json', 'r') as f: check = f.read() print(check) dict1 = json.loads(check) I cannot share the JSON file that is being created for confidentiality reasons, but I have created a dummy json file to share.
{ "ethernet_network": { "first": { "name": "q", "vlanId": "q", "purpose": "q", "smartLink": "q", "privateNetwork": "q", "subnetUri": "q", "maximumBandwidth": "q", "typicalBandwidth": "q" } } } This is the error I am getting:
File "C:\Users\chaudsup\Desktop\python converter\temp.py", line 13, in <module> dict1 = json.loads(check) File "C:\Users\chaudsup\Anaconda3\lib\json\__init__.py", line 348, in loads return _default_decoder.decode(s) File "C:\Users\chaudsup\Anaconda3\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\chaudsup\Anaconda3\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None JSONDecodeError: Expecting value