Returning JSONDecodeError: Expecting value

Viewed 16

I'm trying to open and print my json file but its returning

JSONDecodeError: Expecting value

This is my code

with open(input("Which json. file would you like to read? "),'r') as f:
    weather = json.loads(f.read())
    print(weather)

I really don't know whats the problem, all help appreciated!

1 Answers

This works for me:

import json


# Data to be written
dictionary = {
    "name": "sathiyajith",
    "rollno": 56,
    "cgpa": 8.6,
    "phonenumber": "9976770500"
}

# Serializing json
json_object = json.dumps(dictionary, indent=4)

with open("sample.json", "w") as outfile:
    outfile.write(json_object)

with open(input("Which json. file would you like to read? "),'r', encoding='utf-8') as f:
    weather = json.loads(f.read())
    print(weather)
Related