Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

replace dictionary single quotes to double

dic = [{'one':1, 'two':'t', 'three': {'three.1': 3.1, 'three.2': '3.2' }}]

Desire Output,

[{"one":1, "two":"t", "three": {"three.1": 3.1, "three.2": "3.2" }}]

Tried Code:

ast.literal_eval(json.dumps(dic[0]))

here, Json converting the quotes but also changing the type to str. So I applied ast to change type. at end getting the same output with single quotes.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Output of Json.dumps: json.dumps(dic[0])

'{"one": 1, "two": "t", "three": {"three.1": 3.1, "three.2": "3.2"}}'

Above pre and post single quotes are the issue.

>Solution :

Whats wrong with json.dumps(dic)?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading