Error reading JSON

1

I'm trying to read the JSONs from a folder and get the proper values, I already tested all the JSONs to see if they were valid. The folder with the JSONs is called 'test'

for dirname, dirnames, filenames in os.walk('test'):
    for filename in filenames:
        with open(os.path.join(dirname,filename)) as fd:
            json_data = json.load(fd)
            print json_data

The idea is to go through the whole folder and all the files, reading them and showing the content. But on the run I get one:

  

ValueError: No JSON object could be decoded

This is a JSON:

{
    "test": "Search User 1",
    "url": "http://127.0.0.1:8000/api/v1/user/1/?format=json",
    "status_code": 200,
    "method": "get"
}
    
asked by anonymous 10.11.2014 / 16:23

1 answer

0

As you are reading from a file, the content is possibly a string , so json.load will not work. The other thing is that you are passing to the json.load method of the file descriptor, not a JSON itself.

Use instead:

json_data = json.loads(fd.read())

Read more here .

    
11.11.2014 / 07:25