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

I try to load json file then filter some data, but I failed to load it even

I’m new in learning programming, python, and in this forum as well.
I want to load one json file in VS Code and get some data from it to use it in excel.
But it just fails to load at the beginning when I write.

I wrote this code to view json file.

import json

with open("18july.json") as f:
jsondata = json.load(f)

print(jsondata)

when I run py file, it wrote in terminal

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

PS C:\Users\monst\Downloads\python files> & C:/Users/monst/AppData/Local/Programs/Python/Python310/python.exe "c:/Users/monst/Downloads/python files/tidyjson.py"
Traceback (most recent call last):
  File "c:\Users\monst\Downloads\python files\tidyjson.py", line 4, in <module>
    jsondata = json.load(f)
  File "C:\Users\monst\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 293, in load    
    return loads(fp.read(),
  File "C:\Users\monst\AppData\Local\Programs\Python\Python310\lib\encodings\cp1254.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1502: character maps to <undefined>

You can download my attached json and py file in the link below.
Also my VS Code screenshot when I run it.
https://filetransfer.io/data-package/64l6xzJS

Thanks for your interest.
Thank you.

>Solution :

One solution:

import json
from pathlib import Path

filepath = Path("18july.json")
jsondata = json.loads(filepath.read_bytes())

print(jsondata)
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