While trying to convert the following string into JSON object, I got an error. How can I fix it?
text = '{ "MonitorGroupGuid": "e8b20230-70b6-4348-36f3e3f", "Description": "Root CA", "IsAll":False}'
JsonObject = json.loads(text)
Output:
x = json.loads(x)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 98 (char 97)
CodePudding user response:
You can simply use "" for False are use 0/1, but if you want it as a bool object use false without quotes
"False" datatype is string
just false datatype bool
text = '{ "MonitorGroupGuid": "e8b20230-70b6-4348-36f3e3f", "Description": "Root CA", "IsAll":"False"}' JsonObject = json.loads(text) print(JsonObject)#{'MonitorGroupGuid': 'e8b20230-70b6-4348-36f3e3f', 'Description': 'Root CA', 'IsAll': 'False'}
CodePudding user response:
Replace False
with false
(without quotes)
text = '{ "MonitorGroupGuid": "e8b20230-70b6-4348-36f3e3f", "Description": "Root CA", "IsAll":false}'
JsonObject = json.loads(text)
print(JsonObject) #{'MonitorGroupGuid': 'e8b20230-70b6-4348-36f3e3f', 'Description': 'Root CA', 'IsAll': False}