Home > Blockchain >  error while parsing JSON file, probally a hidden value on the JSON content
error while parsing JSON file, probally a hidden value on the JSON content

Time:01-27

I have this JSON file:

https://drive.google.com/file/d/1zh_fJJNWs9GaPnlLZ459twSubsYkzMi5/view?usp=share_link

Looks normal at first, even using online json schema validators However when parsing it locally, I get error. I tried it with python, nodejs and golang but It's not working. I think it probably has some hidden value that make impossible to parse it

CodePudding user response:

here is the complete solution. comments added against the code.

# read the file as bytes
import chardet
import json
file_path=r"2022_2973.json"
with open (file_path , "rb") as f:
    data= f.read() # read file as bytes
file_encoding=chardet.detect(data)['encoding'] # detect the encoding
print(f"file(bytes) encoding:{file_encoding}") # print encoding

json_data = json.loads(data.decode(file_encoding)) # decode the bytes and load the json data
json_data['snaps'][1]

output:

file(bytes) encoding:UTF-16
{'group': 'Slot',
 'group_order': 1,
 'positions': [{'group': 'Slot',
   'position': 'SLWR',
  • Related