Navneet
Navneet

Reputation: 393

String enclosed inside double quotes(") causes error with json.loads()

I see a weird behavior with double quotes with json.loads(). In the code given below x prints fine.

I want to understand reason for error when I print the value of y.
Why is 'a' printed inside single quotes when its actually inside double quotes.

import json

x = '[["a"]]'
y = "[['b']]"

print(json.loads(x))
print(json.loads(y))

Output

[['a']]  
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 3 (char 2)

Upvotes: 0

Views: 64

Answers (1)

Emanuele Scarabattoli
Emanuele Scarabattoli

Reputation: 4469

The JSON specification does not allow you to use single quotes for strings as explained here:

https://www.w3schools.com/js/js_json_syntax.asp

Upvotes: 1

Related Questions