I have a program that involves sending python dicts that are converted into json using json.dumps back and forth to a server. I have one json response coming back from the server, which I then use json.loads on. When I try to do this for a second json response, I get this error: “raise JSONDecodeError(“Extra data”, s, end)
json.decoder.JSONDecodeError: Extra data: line 3 column 1 (char 1455)”
I’m not sure how to fix this but I need to be able to access different variables inside both of the json strings/python dicts. Here’s the relevant code:
First dictionary/string:
firstDict = {"age": "20"}
firstJson = json.dumps(firstDict) + 'n'
s.sendall(bytes(firstJson, encoding = "utf-8"))
jsonData += s.recv(8012).decode() + 'n'
pyData = json.loads(jsonData)
ageVar = pyData["age"]
print(idVar)
Second:
secDict = {"color": "red"}
secJson = json.dumps(secDict) + 'n'
s.sendall(bytes(secJson, encoding = "utf-8"))
jsonAgain += s.recv(8012).decode() + 'n'
pyAgain = json.loads(jsonAgain)
colorVar = pyAgain["color"]
print(marksVar)
Any help/advice would be greatly appreciated!
I’m not really sure how to fix this, I’ve tried googling but I couldn’t find anything relevant to my specific problem.
Alexa Halpert is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3