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

Version 1.7.1 reported an error in Pycharm #21

Open
Fan-CR opened this issue Nov 22, 2023 · 2 comments
Open

Version 1.7.1 reported an error in Pycharm #21

Fan-CR opened this issue Nov 22, 2023 · 2 comments

Comments

@Fan-CR
Copy link

Fan-CR commented Nov 22, 2023

It cannot convert the dict data type to the JSON data type in Python IDE (Pycharm)
It shows the error: Unexpected character (''' (code 39)): was expecting double-quote to start field

@SadSack963
Copy link

SadSack963 commented Nov 24, 2023

This is not a problem with Json_Parser. JSON strings must be enclosed in double quotes. See Introducing JSON
Unfortunately, Python has a tendency to enclose the strings in single quotes instead - at least, in Windows. I'm not sure if the issue is with Python, requests or the Operating system / Terminal.
Your best bet is to run the JSON through a text editor and search/replace the single quotes with double quotes.
Be careful not to replace single quotes inside a string though.
For a dictionary, try this:

import json
my_dict = {
    'a': 1,
    'b': 2,
    'c': 3,
}
print(json.dumps(my_dict))

One option that seems to work for me when getting data from a request (I cannot guarantee in all situations):

import requests
import json
import ast
...
response = requests.get(url=api_url, params=api_params, headers=api_headers)
print(json.dumps(ast.literal_eval(response.text)))

HTH

@MiTuLittle
Copy link

MiTuLittle commented Jan 17, 2024

This question was find in the latest version(1.7.1), and the single quotes in string won't reported Error in Pychram at the previous version

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

3 participants