0

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.

4
  • Try with json.load() and pass the file directly. My glass ball suggests: encoding issue. Commented Mar 3, 2016 at 8:45
  • even that throws the same exception @dhke Commented Mar 3, 2016 at 8:50
  • Ah. I must have been blind. "name": xyz isn't valid JSON. xyz isn't a literal. Did you mean "name": "xyz"? Commented Mar 3, 2016 at 8:58
  • yes, you are right! thanks Commented Mar 3, 2016 at 9:21

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.