0

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)
1
  • Replacing False with "False" solves this problem. But I need to maintain my string format. Commented Dec 8, 2021 at 15:37

2 Answers 2

2

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'}

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

Comments

1

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}

2 Comments

There is still a problem associated with this solution. Python recognises only False as a boolean, not false.
If you try print(JsonObject["IsAll"] is False), it prints True. So I think the value is recognized correctly.

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.