Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should read_json() work when file contents uses single quotes? #671

Open
stxue1 opened this issue Jul 2, 2024 · 0 comments
Open

Should read_json() work when file contents uses single quotes? #671

stxue1 opened this issue Jul 2, 2024 · 0 comments
Assignees

Comments

@stxue1
Copy link
Collaborator

stxue1 commented Jul 2, 2024

The JSON standard requires double quotes for strings and single quotes are disallowed. However, python tends to output certain values with single quotes. For example:

>>> a = ["hello"]
>>> print(a)
['hello']
>>> import json
>>> json.loads(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not list
>>> json.loads('["hello"]') # needs to be double quoted
['hello']

There is a unit test that depends on this behavior; it tries to take the python stringified output into the read_json() standard library function. However, the command section will output ['key1', 'key2'], which uses single quotes, meaning this is not valid JSON and failing the unit test.

@jdidion jdidion self-assigned this Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants