0

I get the below error when i try to read a JSON file, not sure what needs to be corrected:

C:\Users\prabhjot2600\PycharmProjects\PythonPractise\venv\Scripts\python.exe C:/Users/prabhjot2600/Desktop/Prabh/alien_invasion/test.py
Traceback (most recent call last):
  File "C:/Users/prabhjot2600/Desktop/Prabh/alien_invasion/test.py", line 26, in <module>
    data = json.loads(people_string)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 11 column 21 (char 192)

My code is simply reading a JSON file and printing its data. I have checked my JSON data also which looks correct and also formatted it to see if there were any errors left but still cant read the JSON

import json

people_string = '''
{
  "people": [
    {
      "name": "Prabhjot Singh",
      "phone": "9999596310",
      "emails": [
        "[email protected]",
        "[email protected]"
      ],
      "hasLicence": True
    },
    {
      "name": "Sunny Rana",
      "phone": "9999988888",
      "emails": null,
      "hasLicence": False
    }
  ]
}
'''


data = json.loads(people_string)
print(data)
1
  • 4
    JSON uses true and false instead of True and False. Commented Mar 11, 2020 at 6:56

1 Answer 1

1

JSON stands for JavaScript Object Notation.
So it is subset of Javascript's syntax.
Javascript uses true and false keyword as literal boolean values.
(Whereas python uses True and False).

Therefore, you should use true and false instead of True and False.
See https://www.json.org/json-en.html for detailed syntax.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.