0

i am trying to create blog page using flask and i want to take input file as a config.json which i have created. Please help me i am getting json decoder error i also tried to convert str to utf8 but its showing the error

with open('config.json', 'r', encoding ='utf-8') as c:
    params = json.load(c)["params"]

json content:

{
    "params":
    {
        "local_server":"True",
        "local_uri":"mysql://root:@localhost/codingthunder",
        "prod_uri":"mysql://root:@localhost/codingthunder",
        "fb_url":"https://facebook.com/codingthunder",
        "tw_url":"https://twitter.com/codingthunder",
        "gh_url":"https://github.com/codingthunder",
        "blog_name":"Coding Thunder",
        "tag_line":"A Blog liked by Programmers"
    }
}

output log:

PS C:\Users\ASHISH\Desktop\Coding\Flask> python -u "c:\Users\ASHISH\Desktop\Coding\Flask\Blog Page\main.py"
Traceback (most recent call last):
  File "c:\Users\ASHISH\Desktop\Coding\Flask\Blog Page\main.py", line 7, in <module>
    params = json.load(c)["params"]
  File "C:\Users\ASHISH\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Users\ASHISH\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\ASHISH\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\ASHISH\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

1 Answers1

1

Expecting value: line 1 column 1 (char 0) hints that there is no value at the beginning of the file, so no content in the parsed file.

This could mean, that

  • the file is empty
  • you opened the wrong or a non existing file
  • you are using a relative path and your working direktory is wrong (e.g. the direktory you execute your program in)
wuerfelfreak
  • 2,363
  • 1
  • 14
  • 29