0

I want to load a json file. And my code snipped like that:

def getInfoFromJson (dir):
    with open(dir, 'r') as f:
        data = json.load(f)
        objectId = data['id']

Also when I print "f" the output like that:

<_io.TextIOWrapper name='./jsonfiles/2021-04-10_21-05-59_UTC.json' mode='r' encoding='UTF-8'>

But when I try to run I get an error like that:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I tried to several solutions but I cannot solve this. What is the problem? How can I solve this?

akasaa
  • 1,282
  • 4
  • 13
  • 33
  • Check following thread. [link] (https://stackoverflow.com/questions/20199126/reading-json-from-a-file) – Gokberk Yar Apr 11 '21 at 15:49
  • 1
    Well showing that you've got a file object is all well and good, but Python complains about the actual contents of the file so maybe you should look at that? And if there's nothing visibly wrong with it, check that there are no leading invisible characters e.g. BOM? – Masklinn Apr 11 '21 at 15:50
  • That aside, `dir` is [a builtin function](https://docs.python.org/3/library/functions.html#dir) and it's generally considered bad form to shadow those even though `dir` is not the most commonly used one, especially outside of interactive shells. – Masklinn Apr 11 '21 at 15:51
  • Oh! When I run this script on my PC there is no error. But when I run this script on docker container I get this error. I don't understand why its happening – akasaa Apr 11 '21 at 16:05

0 Answers0