deepak
deepak

Reputation: 349

How to load a JSON file in python 2.7

I am not able to load the following 'data.json' file in python 2.7.11,

file data.json

{
  "name":xyz,
  "age":12
}

The code i am using the load the above file,

import json
json_data = open ('data.json').read ()
json.loads(json_data)

I always get the following error

ValueError: No JSON object could be decoded

In the meantime,i also tried using yaml.load and it worked fine. But i wanted to know what is that i am doing wrong.

Upvotes: 0

Views: 7881

Answers (1)

junoon53
junoon53

Reputation: 41

Your JSON is invalid.

Remember, if you're using alphabetical characters in a json Value, it's a string. So you have to write it within double quotes, like so:

{
  "name":"xyz",

  "age":12

}

Hopefully, this fix should solve your problem.

Upvotes: 3

Related Questions