-1

I know this has been asked before so this is definitely getting marked as duplicate but whatever. I've been stuck on this for days and none of the other solutions have done a thing. All I am trying to do is load the json into a python program.

Attempt 1:

def get_post(number, target):
#path = str(number) + ".json"

post = json.loads('1.json')

return post

Attempt 2:

with open("1.json") as infile: post = json.loads("1.json")

And neither works. I get

  File "posthandler.py", line 34, in <module>
  with open("1.json") as infile: post = json.loads("1.json")
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
  return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 342, in decode
  raise JSONDecodeError("Extra data", s, end)

Here's my json:

{
"name" : "test"
}

Note I have looked at the hex of the file and nothing seems out of place

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

0

Let me iterate my point in the answer:

Either attempt is almost right but you should use the file handler in your load function call.

Try this:

with open("1.json", "r") as infile: 
    post = json.load(infile)
Zhiya
  • 610
  • 2
  • 7
  • 22